嘿伙计们,有没有人遇到过运行程序命令后不会退出的 JSL 脚本?我正在尝试确定 outlook 是否打开,如果没有打开。这是我的代码。任何帮助,将不胜感激:
Names Default To Here( 1 ); // Make sure variables are stored in this procedure
Clear Log(); // Clear the JMP Log - Select View - Log
// Get the current windows processes (process list) using teh wmic.exe
windowsProcesses = RunProgram(executable("wmic"),options({"process list"}),
readfunction(function({this},write(this<<READ></READ>非常感谢您的帮助。我是 JMP 的新用户,就我目前所见而言,这个社区非常好。
你可能会在这方面取得一些成功;我在过去使用时取得了不同的成功开始从 JMP 中分离程序。
rp=RunProgram(Executable("cmd.exe"),options("/C start outlook.exe"))
当 RunProgram 启动一个外部程序并且您不使用 ReadFunction("text") 时,一个 RunProgram 对象返回给 JSL 以管理外部程序(在示例中为 rp)。 当该对象被销毁时,由 rp=0;也许,或者通过不将其保存在 JSL 变量中,JMP 会等待外部程序完成。 如果开始分离 outlook,然后 rp<
ReadFunction("Text") 也让 RunProgram 等待,为了方便起见,只返回所有输出而不是一个对象。
德鲁,
我没有加载 wmic.exe,我对使用它不感兴趣。您没有提到 wmic 或 outlook 是否发生错误。
Run Program() 执行外部可执行文件并运行命令(选项)。 我希望控制权永远不会返回到 JMP,因为在执行 Outlook 时没有命令将控制权返回给程序。我建议您使用 Open() 以防万一。如前所述,我没有使用 wmic.exe;它运行一个命令并结束,还是保持会话打开? 这也可能导致运行程序永远不会将控制权返回给 JMP。
不管怎样,下面是一个使用 tasklist.exe 的脚本。
此外,以防万一其他人想使用此脚本,我包含了使用 where.exe 查找 Outlook.exe 路径的代码。 我也有 32 位 Outlook,但我的路径与你的不同。请注意,显示 outlookpath 需要等待 3 秒。 可以删除该标题代码。
Names Default To Here( 1 ); // Make sure variables are stored in this procedure
Clear Log(); // Clear the JMP Log - Select View - Log
//find outlook
outlookpath = "";
cmd1 = "\[/c where /R "C:\Program Files (x86)" OUTLOOK.EXE]\";
rp0 = RunProgram(Executable("CMD.EXE" ),
Options({Eval(cmd1)}),
Read Function("text")
);
outval = words(Trim(rp0), "\!n");
if(StartsWith(outval[1], "C:\Program Files"), outlookpath=outval[1]);
//only run this if not found
if (outlookpath =="", //try for 64 bit version of excel
cmd1 = "\[/c where /R "C:\Program Files" OUTLOOK.EXE]\";
rp0 = RunProgram(Executable("CMD.EXE" ),
Options({Eval(cmd1)}),
Read Function("text")
);
outval = words(Trim(rp0), "\!n");
if(StartsWith(outval[1], "C:\Program Files"), outlookpath=outval[1] );
);
if(outlookpath =="", Caption("Cannot find Excel ... aborting"),
Caption( "Outlook path is: "|| outlookpath) );
wait(3);
caption(remove);
//_____________________________________________________________________________
windowsProcesses = RunProgram(executable("CMD.exe"),options({"/c tasklist /FI \!"IMAGENAME eq outlook.exe\!""}),
readfunction("text")
);
/* to get a list of all processes just use /c tasklist */
show(windowsProcesses);
//
// Check if outlook is open by searching the log file
openYesNo = If(contains(lowercase(Trim(windowsProcesses)),"outlook"),1,0);
// Open Outlook if it is currently closed
If( openYesNo == 0,
Open(outlookpath)
);