The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum
 Origin Forum
 Running an external program

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
dongjinkim Posted - 09/10/1999 : 3:28:00 PM
Hello,

I would like to know if it is possible to run an external program "synchronously" using LabTalk. In other words, when the script executes the external program, it will wait until the program finishes before continuing.
Thanks again.

3   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 11/27/2003 : 10:36:20 AM
The following method is not as elegant as those suggested previously but is extremely simple to implement. I use it occasionally for testing and for tasks that are simple enough that I don't mind waiting around for their completion.

1. Create a batch file similar to the one suggested by Greg.

REM - LAUNCH.BAT
@ECHO OFF
START /W "C:\Program Files\My Application.EXE"
CLS
EXIT

(The last two DOS commands will close the command window without the need of a PIF file.)

2. Use the batch file in the following LabTalk script...

run -e "C:\Program Files\Launch.bat";
type -b "Continue when the command window closes.";

The type -b command opens a message box that suspends script execution until you press its OK button. In this case you would dismiss it when the DOS box closes which indicates that your program is done.

Mike Buess
Origin WebRing Member
jhuntnz Posted - 11/25/2003 : 4:24:14 PM
Hi,

Another option that is more efficient but more complicated and requires you to have Visual C++ or at least the runtime library is this.

Declare in a header:
// Include from the Microsoft Visual C runtime to run the command sync
#pragma dll("MSVCRT");

int _spawnl(
int mode,
const char *cmdname,
const char *arg0,
const char *argn,
const char *null
);

This means u need msvcrt.dll installed on your computer - it should be in windows\system. Comes with Visual C++ and lots of other programs the use MFC so hopefully its not too hard to come by.

Now Origin C is a bit limited it seemed so you might need to modify the declaration depending on how many arguments you want to pass to the function. The last argument has to be a NULL and you can modify the number of arg0 to suit you.
Then use it like this:
_spawnl(0 (default - means that it is synchronous (will wait for completion of exe and return error value), "me.exe", "arg1", NULL, NULL);


Hope its helpful to someone.
greg Posted - 09/14/1999 : 1:01:00 PM
While there is no built-in command to run an application synchronously, you can resort to using DOS (remember DOS?) to accomplish the same thing:

The idea is to use LabTalkTM to launch a batch file and then run a loop to 'watch' your system for a specific event. The DOS batch file synchronously runs your application with the START command and then creates the event that your script is watching for.

Origin Professional users have an easier time doing this since they can use the File Utilities Module (FUM) to read or write any kind of file, while Origin Standard users need to find some command that can read external files. Aside from importing-related commands, there is one object which allows reading from (and writing to) a file: the INI object.

Here's an outline of what to do:


  1. Create the batch file in Notepad

    START /W "C:\Program Files\My Application.EXE"

    ECHO [message] > C:\DONE.INI

    ECHO new=Completed normally >> C:\DONE.INI

  2. Save the file

    In this case we'll call it C:\Program Files\LAUNCH.BAT

  3. Run your script file


    ini.get.filename$="C:\DONE.INI";
    ini.message.new$=waiting;
    run -e "C:\Program Files\LAUNCH.BAT";
    for(done=0;done<1 ; ) {
    %A=ini.message.new$;
    if("%A"=="Completed normally") done=1;
    }
    ini.message.new$=None;
    // remainder of script goes here ...



The script begins by making sure the Key value (new) in the [message] section of DONE.INI is set to "waiting".
Then the batch file is started which launches your application and Waits for it to complete.
After your application completes, the batch file creates DONE.INI (or overwrites) with the Key value 'new' set to "Completed normally".
This is just what the for loop in the script has been waiting for. Your script can now continue. (In this case I also set the 'new' Key to "None".)


You can create a PIF file that will close the DOS box created by LAUNCH.BAT by right-clicking on the DOS icon in the upper left of the DOS box and selecting Properties. Check the 'Close on Exit' box and OK out of the dialog.

[This message has been edited by Greg (edited 09-14-99).]


The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000