Call External Application

I would like to call an external application (.bat file using the DOS prompt) using a button click in the Ignition vision module. I found the system.util.execute function but I’m unsure how to specify the “program” and “parameter” strings. Any suggestions?

Thanks.

It’s been a while, but when I used it last, I remember doing it like this:

If I wanted to do the equivalent of typing this in the command prompt:

c:\script.bat -run=windowed

I’d set up the strings like this:

Program string: “c:\script.bat”
Parameter string: “-run=windowed”

Then, just throw them in an array, and pass that array to the execute function.

Hope this helps.

Thanks for your suggestion Kevin. I didn’t have much luck. Here is my code:

parray=[‘C:\SQLSync\Sync.bat’, ‘-run=windowed’]
system.util.execute(parray)

I tried various versions of the ‘-run=windowed’ string but no luck. Do you suppose I need to make the program path ‘C:\windows\system32\cmd.exe’?

Cheers,
Soren.

I’ve been able to launch Windows executables using system.util.execute, but it doesn’t seem to do anything if you pass it a batch file.

I haven’t tried it, but what about using cmd.exe as the first string, and the path to the batch file as the second string?

Already tried the cmd.exe approach you suggested. Also no luck…

Googling showed me this might work:

cmd /C start C:/test.bat

So, if this does work,

string 1 is “c:\path_to\cmd.exe”
string 2 is “/C”
string 3 is “start”
and string 4 is “C:/test.bat”

In my trials at the command prompt, this worked.

Good luck!

Well done Kevin :thumb_left:

I got it working with the following:system.util.execute(["C:\windows\system32\cmd.exe","/C","start","C:\Test.bat","123","456"])where 123 and 456 are 2 parameters being passed to the batch file.

Note that this will leave the cmd window open on the screen. To close it when you’re done, make sure you include an ‘exit’ command as the last line of your batch file.

Excellent! Thanks all. Works like a charm.