cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
Drew
Level I

JSL script - RunProgram seems to crash script

Hey guys, has anyone encountered a JSL script that won't quit after a run program command?  I am trying to determine if outlook is open and if not open it.  Here is my code.  Any help would be appreciated:

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)))
);

// Wait enough time for windows processes to get logged
Wait(30);

// Temporarily save log file for use later
Save Log( "C:\TEMP\Jmplog.txt" );

// Load the newly saved log file
windowsProcessText = Load Text File( "C:\TEMP\Jmplog.txt" );

// Check if outlook is open by searching the log file
openYesNo = If(contains(windowsProcessText,"Outlook"),1,0);

// Open Outlook if it is currently closed
If( openYesNo == 0,
    RunProgram(Executable("C:\Program Files (x86)\Microsoft Office\Office16\Outlook.exe"))
    );
1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: JSL script - RunProgram seems to crash script

Drew,

I don't have wmic.exe loaded and I am not interested in using it.  You did not mention if the error is happening with wmic or outlook.  

Run Program() executes the external executable and runs the commands (options). I expect control never returned to JMP because there were no commands to return control to the program when Outlook was executed.  I suggest you use Open() just in case.  As stated I have not used wmic.exe; does it run one command and end, or does it keep the session open? This could also cause Run Program to never return control to JMP.  

 

Anyway, below is a script using tasklist.exe.

 

Also, just in case others would like to use this script, I included the code to find the path of Outlook.exe using where.exe. I also have 32 bit Outlook but my path was different than yours.  Note, there is a 3 second wait that displays the outlookpath. That caption code can be removed.

 

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)
 );

   

View solution in original post

4 REPLIES 4
gzmorgan0
Super User (Alumni)

Re: JSL script - RunProgram seems to crash script

Drew,

I don't have wmic.exe loaded and I am not interested in using it.  You did not mention if the error is happening with wmic or outlook.  

Run Program() executes the external executable and runs the commands (options). I expect control never returned to JMP because there were no commands to return control to the program when Outlook was executed.  I suggest you use Open() just in case.  As stated I have not used wmic.exe; does it run one command and end, or does it keep the session open? This could also cause Run Program to never return control to JMP.  

 

Anyway, below is a script using tasklist.exe.

 

Also, just in case others would like to use this script, I included the code to find the path of Outlook.exe using where.exe. I also have 32 bit Outlook but my path was different than yours.  Note, there is a 3 second wait that displays the outlookpath. That caption code can be removed.

 

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)
 );

   

Craige_Hales
Super User

Re: JSL script - RunProgram seems to crash script

nice!

Craige
Craige_Hales
Super User

Re: JSL script - RunProgram seems to crash script

You might have some success with this; I've had mixed success in the past using start to detach a program from JMP.

rp=RunProgram(Executable("cmd.exe"),options("/C start outlook.exe"))

When RunProgram starts an external program and you don't use ReadFunction("text"), a RunProgram object is returned to JSL to manage the external program (rp, in the example). When that object is destroyed, by rp=0; perhaps, or by not keeping it in a JSL variable, then JMP waits for the external program to complete. If start detaches outlook, then rp<<IsReadEOF will be 1.

ReadFunction("Text") also makes RunProgram wait, and as a convenience just returns all of the output rather than an object.

 

Craige
Drew
Level I

Re: JSL script - RunProgram seems to crash script

Really appreciate the help.  I am very new user to JMP and this community is really good from what I have seen so far.