Invoking External Programs

os.execute()

os.execute() allows one to execute external programs.  The behaviour will differ a little depending on your operating system – Windows/Linux/Unix/Mac OS X etc.

This code snippet shows some of the syntax you can use:

-- Notice the need to enclose a file path with spaces with " characters
-- Plus the need to escape the string correctly.
os.execute('\"C:\\Program files\\iNTERFACEWARE\\Chameleon\\Simulator.exe\"')
-- Windows can also take / separators which makes this syntax work too
os.execute('"C:/Program files/iNTERFACEWARE/Chameleon/Simulator.exe"')

Quite often one needs to chain a few commands together. For instance changing the working directory can be very important. This syntax works:

os.execute('cd C:\\temp && run.bat')

Tip: All os.execute() actions will run in test and live mode. In this example you might want to prevent the simulator from running in live mode.

The solution is simply to use iguana.isTest() to prevent the code from running.

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.