<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: JSL script - RunProgram seems to crash script in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63325#M33979</link>
    <description>&lt;P&gt;Drew,&lt;/P&gt;&lt;P&gt;I don't have wmic.exe loaded and I am not interested in using it.&amp;nbsp; You did not mention if the error is happening with wmic or outlook.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; I suggest you use Open() just in case.&amp;nbsp; 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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, below is a script using tasklist.exe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; Note, there is a 3 second wait that displays the outlookpath. That caption code can be removed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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)
 );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Jul 2018 05:39:30 GMT</pubDate>
    <dc:creator>gzmorgan0</dc:creator>
    <dc:date>2018-07-19T05:39:30Z</dc:date>
    <item>
      <title>JSL script - RunProgram seems to crash script</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/61861#M33336</link>
      <description>&lt;P&gt;Hey guys, has anyone encountered a JSL script that won't quit after a run program command?&amp;nbsp; I am trying to determine if outlook is open and if not open it.&amp;nbsp; Here is my code.&amp;nbsp; Any help would be appreciated:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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&amp;lt;&amp;lt;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"))
    );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jun 2018 00:07:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/61861#M33336</guid>
      <dc:creator>Drew</dc:creator>
      <dc:date>2018-06-29T00:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script - RunProgram seems to crash script</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63325#M33979</link>
      <description>&lt;P&gt;Drew,&lt;/P&gt;&lt;P&gt;I don't have wmic.exe loaded and I am not interested in using it.&amp;nbsp; You did not mention if the error is happening with wmic or outlook.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; I suggest you use Open() just in case.&amp;nbsp; 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.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyway, below is a script using tasklist.exe.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp; Note, there is a 3 second wait that displays the outlookpath. That caption code can be removed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;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)
 );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 05:39:30 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63325#M33979</guid>
      <dc:creator>gzmorgan0</dc:creator>
      <dc:date>2018-07-19T05:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script - RunProgram seems to crash script</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63335#M33984</link>
      <description>&lt;P&gt;nice!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 10:10:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63335#M33984</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-07-19T10:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script - RunProgram seems to crash script</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63336#M33985</link>
      <description>&lt;P&gt;You might have some success with this; I've had mixed success in the past using &lt;EM&gt;start&lt;/EM&gt; to detach a program from JMP.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;rp=RunProgram(Executable("cmd.exe"),options("/C start outlook.exe"))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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 &lt;EM&gt;start&lt;/EM&gt; detaches outlook, then rp&amp;lt;&amp;lt;IsReadEOF will be 1.&lt;/P&gt;
&lt;P&gt;ReadFunction("Text") also makes RunProgram wait, and as a convenience&amp;nbsp;just returns all of the output rather than an object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jul 2018 11:14:29 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63336#M33985</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2018-07-19T11:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: JSL script - RunProgram seems to crash script</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63672#M34065</link>
      <description>&lt;P&gt;Really appreciate the help.&amp;nbsp; I am very&amp;nbsp;new user to JMP and this community is really good from what I have seen so far.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 17:11:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-script-RunProgram-seems-to-crash-script/m-p/63672#M34065</guid>
      <dc:creator>Drew</dc:creator>
      <dc:date>2018-07-23T17:11:33Z</dc:date>
    </item>
  </channel>
</rss>

