To run programs from JScript, you can use XSIUtils.LaunchProcess.
Here’s a simple example that does a dir on C:\Program Files, redirects the output to a text file, and then uses Notepad to open the text file:
var sPath = XSIUtils.Environment("TEMP"); XSIUtils.LaunchProcess( 'cmd /C "dir > ' + sPath + '\\dir222.txt"', false, "C:\\Program Files" ); XSIUtils.LaunchProcess( 'notepad ' + sPath + '\\dir222.txt', false, "C:\\" );
The third argument to LaunchProcess will be the current working directory of the launched process. So in the above example, I’m doing a dir of C:\Program Files (because cmd opens with C:\Program Files as its current directory).
If the exe is not in the system PATH, then you need to specify the full location:
var sCommandLine = "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\devenv.exe"; var sStartupDirectory = Application.InstallationPath( siWorkgroupPath ); XSIUtils.LaunchProcess( sCommandLine, false, sStartupDirectory );
In the above example, I’m using my workgroup location as the current directory, so when I do File > Open in Visual Studio, by default I will be looking in my workgroup location.
Cool, Is it possible to make it work in python?
Sure
from win32com.client import Dispatch as disp
siut = disp(‘XSI.Utils’)
sPath = siut.Environment(“TEMP”)
siut.LaunchProcess( ‘cmd /C “dir > ‘ + sPath + ‘\\dirTest.txt”‘, False, “C:\\Program Files” )
siut.LaunchProcess( ‘notepad ‘ + sPath + ‘\\dirTest.txt’, False, “C:\\” )
[/python]
With Python, you can also run EXEs like this:
import subprocess
subprocess.Popen( “notepad.exe”, False )
[/python]
or this:
import subprocess as sp
run = [r’C:\Windows\System32\PING.EXE’]
args = r’-n 50 google.com’
run.extend(args.split())
sp.Popen(run)
[/python]
thank you, I will give tihs a try.
I want to launch a “xsibatch -script” from a toolbar to process some scripts on a Model, without interferring with my actual scene.