## XSIUtils.LaunchProcess

### Introduced

v5.0

### Description

Launches an external process such as a batch file, external text editor or command prompt.
On Linux this method is identical to the System command except that no message is logged in the Script History window. On Windows the System command will pop up a temporary command prompt, but this method will not. For further details please refer to the Win32 documentation for CreateProcess.

### C# Syntax

    Int32 XSIUtils.LaunchProcess( String in_AppAndCommandLineArgs, Boolean in_bBlock, Object& in_Directory );

### Scripting Syntax

    oLong = XSIUtils.LaunchProcess( CommandLine, [Blocking], [StartupDirectory] );

### Return Value

Long - When blocking is set to true the exit code of the child process is returned

### Parameters

Parameter | Type | Description
--- | --- | ---
CommandLine | String | The executable name and any command line options. Be sure to use extra quote characters if there are space characters in any path or filename in the string. For example the quotes in '"C:\My Programs\myeditor.exe"' prevent Softimage from trying to execute an executable named 'C:\My.exe'.
Blocking | Boolean | If blocking is set to true then Softimage will not return from this method until the child process has finished execution. Default Value: false
StartupDirectory | String | An initial directory for the process. When not set the Process will launch with the same directory as the current Softimage working directory. This option is useful when launching command prompts.

### Examples

#### 1. VBScript Example

    '
    '       This example launchs a command prompt with the directory set
    '       to the current user path
    '
    ' The new command prompt inherits all the environmental variables
    ' from Softimage so it will behave like a Softimage command prompt
    startDir = Application.InstallationPath( siUserPath )
    bBlocking = false               ' We don't want the command prompt to freeze Softimage
    if Application.Platform = "Win32" then
            XSIUtils.LaunchProcess "cmd /C start cmd /K title Softimage Command Prompt", bBlocking, startDir
    else
            XSIUtils.LaunchProcess "xterm", bBlocking, startDir
    end if

#### 2. JScript Example

    /*
            This example shows how the XSIUtils.LaunchProcess method can be used to execute an
            external process. In this case it shows spdlcheck can be used to test a spdl directly
            from within scripting.
    */
    if ( Application.Platform == "Win32" )
    {
            var slash = "\\" ;
    }
    else
    {
            var slash = "/" ;
    }
    // Path to one of the spdl files that ships with Softimage
    var twistSpdl = Application.InstallationPath( siFactoryPath ) + slash + "Application"
                            + slash + "spdl" + slash + "twistop.spdl" ;
    var strResults = SpdlCheckFile( twistSpdl ) ;
    if ( strResults == "" )
    {
            LogMessage( "Spdl is OK" ) ;
    }
    else
    {
            LogMessage( "Spdl is busted:\n" + strResults ) ;
    }
    // Helper function that runs spdlcheck on the provided file path.
    // Returns:
    //  - an empty string if the spdl is ok.
    //  - the error details output by spdlcheck if there is a problem.
    function SpdlCheckFile( in_file )
    {
            // We will launch "spdlcheck" and tell it to output
            // its results into a temporary file
            var tmpFile = Application.InstallationPath( siUserPath ) + slash
                            + "spdlcheckoutput.tmp" ;
            var cmd = "spdlcheck -nologo -noverbose -out \"" + tmpFile + "\" \"" + in_file + "\"";
            Logmessage( "This command line will be executed:\n" + cmd ) ;
            // Specify true for the blocking argument so that our script waits until spdlcheck
            // has finished before trying to read the output file
            XSIUtils.LaunchProcess( cmd, true ) ;
            var oFSO = new ActiveXObject( "Scripting.FileSystemObject" ) ;
            var oTextFile = oFSO.OpenTextFile(tmpFile, 1 ) ;
            // We expect a string like:
            // "Compilation succeeded c:\Softimage\<....>\Application\spdl\twistop.spdl (XSI Object)"
            fileAsStr = oTextFile.ReadAll() ;
            oTextFile.Close() ;
            oFSO.DeleteFile( tmpFile ) ;
            // If we find the string "Compilation succeeded" then we would know that
            // we were successful
            if ( -1 != fileAsStr.search( /Compilation succeeded/ ) )
            {
                    return "" ;
            }
            // Return the error details
            return fileAsStr ;
    }

### See Also

System