cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
AD1
AD1
Level III

Running external program with JMP

Hi,

I am new user and would like to know a couple of things about Run Program which was not clear to me from the 

documentation. I am using JSL to run an external program which starts its own gui. 

1. Is there a way to embed this gui into JMP or force it to be contained within the JMP gui?

2. It initially starts a command line on windows and load stuff and then asks for a file dialog which

for me is a standard file. Is it possible to automatically supply this and suppress the file dialog opening?

3. It generated matlab plots as it is written in matlab. Can I force the matlab plots to be contained in JMP gui?

4.  Most important: I am able to call the external program but the script part after Run Program is executed

even if the program hasn't finished. Since I have to copy files after external program finishes, the copied files

are incomplete.

I am trying to do this (any corrections are welcome):

some_function = Function({x},
    //This function I wish to execute after the some_exe is finished
   //or I have closed all of its gui components manually.
);

Show("this executes before run program"); //ok, as expected.
run_program = Run Program(
    Executable(some_exe), //Works but execution through .bat doesn't.
    Read Function(some_function),
);
Show("This also executes before external program finishes. Why?"); 

2 REPLIES 2
Craige_Hales
Super User

Re: Running external program with JMP

answering (4), why does JSL, after the RunProgram call, run too soon?

RunProgram can launch several ways. Since you provided a ReadFunction, RunProgram will return immediately and hands back a RunProgram object that has methods you can test:

 

		While( run_program << canread | run_program << canwrite | !(run_program << isreadeof), 
		//	show(run_program<<canread,run_program<<canwrite,run_program<<isreadeof);
			Wait( .1 )
		);

 

The example above depends on the external program closing the connection when it terminates. It waits briefly after each check, then looks again to see if the program is still around, waiting to read from JMP, write to JMP, or just has not closed the connection that JMP might be able to read from later. The commented show() will help figure it out.

 

A simpler approach is to leave out the ReadFunction. Then RunProgram just returns the text the external program printed, after the external program finishes. You can then process the returned text and any files the external program created using JSL (to open windows, make graphs, etc.)

 

The complicated way: If you are expecting JMP to show updates in JMP-owned windows while the external program runs, you'll need to process the ReadFunction text with JSL that reacts to the text. This is complicated because text can arrive a few characters at a time; you'll need a strategy for collecting the bits of text into a JSL string and determining when the text command is complete and not throwing away part of the next text command. The data for JMP to display can either be in the text or in a file, but the received text command is how you know the data is available. (I don't recommend watching for a file to become available because you might start using a file that is only half-written by the external program.)

Writing the ReadFunction to work well: try something like this: 

while(this<<canread, // untested, approximately correct code...
    buffer = buffer || (this<<read); 
    wait(0); 
    buffer = process(buffer)
)

the process function uses your strategy to determine if the buffer holds a complete text command(s), processes the command(s), removes the command(s) and returns whatever is left in the buffer that will become part of the next text command. Note that process(buffer) should return the entire buffer unchanged if the command is not complete and should process all the text commands in the buffer that are complete.

And, in all of the above complicated part, I've completely ignored how the external program has to be written to generate the printed output that JMP can interpret as text commands. And what a strategy might look like: new-lines or commas or etc to delimit complete commands.

 

Craige
AD1
AD1
Level III

Re: Running external program with JMP

Thanks for a detailed reply. The problem is that I am not looking at a text output. I was hoping if there was a way to contain the ui windows

such as matlab plots created and actively updated by the external program. The external program just stops with the last plot which remains visible and I have to close it manually. But capturing a ui window and putting it inside jmp is I guess too much to ask of any application. 

 

Thanks