Softimage SDK Programmer's Guide > Script Development > Issues in Batch Scripting >

# Running Scripts in Batch Mode

To run a script in batch mode, you must set the environment and then start Autodesk Softimage with the script.

## Setting the Environment

Before running a script in batch mode, you should first set the environment properly:

- On Windows, open a command prompt. To do this, choose Programs Autodesk Autodesk Softimage 2012 Command Prompt from the Windows Start menu.

- On Linux, open a shell and source the .xsi_2012 Softimage resource file.

## Launching Autodesk Softimage with a Script

To run the program and a script in batch mode, start Autodesk Softimage with the -script switch, specifying your script file name. There are several ways to do this, depending on whether you need to specify the scripting language, specify the procedure to run, or supply values for arguments.

### To run simple scripts in batch mode

To run a simple VBScript file named myscript.vbs, use the following syntax at the command prompt:

    xsi -script myscript.vbs

### To specify the scripting language in batch mode

The scripting language is determined by the file name extension according to information in the registry: by default, this is .vbs for VBScript, .js for JScript, and .pys for Python. If your script file uses a different extension, you can specify the language explicitly with the -lang switch. For example, to run a script file named myscript.xxx, use one of the commands below:

    xsi -script myscript.xxx -lang VBScript
    xsi -script myscript.xxx -lang JScript
    xsi -script myscript.xxx -lang Python

### To specify a procedure in batch mode

By default, when you run a script in batch mode, only global code is executed. If your script contains procedures, you can use the -main switch to specify which procedure to run. For example, to run a procedure named myproc in a VBScript file named myscript.vbs, use the following syntax:

    xsi -script myscript.vbs -main myproc

Important

Even when a procedure is specified, global code may be executed before the procedure is called. This is a side effect of parsing the script with some scripting engines. To be certain that your script behaves predictably in all situations, do not mix global code and procedures.

Note

Softimage cannot directly call procedures in Python. However, procedures called from global code or other procedures work properly. You can use a small VBScript or JScript script to create a list of arguments and call a Python procedure.

### To supply arguments in batch mode

If your procedure requires arguments, you can specify them after the -args switch. For example, if the procedure myproc in myscript.vbs requires two arguments named myargname1 and myargname2, you can run the procedure and set the argument values with the following syntax (it should all be on one line):

    xsi -script myscript.vbs -main myproc
    -args -myargname1 myargvalue1 -myargname2 myargvalue2

Note

If you specify arguments with the -args switch but do not specify a procedure with the -main switch, then Softimage will look for a procedure called main and run it. If there is no procedure called main, global code is executed and the command line arguments are ignored.