嘿伙計們,有沒有人遇到過運行程序命令後不會退出的 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)
);