MAXScript Tools and Interaction with 3ds Max > Miscellaneous Functions >

# Executing External Commands

MAXScript provides several methods for executing external programs

    DOSCommand <command_string>

Takes a DOS command as a string and send it to the system for execution.

You can use this function to launch other programs, or perform such tasks as gathering all the material texture and displacement image files in your scene into one folder.

Returns an integer which is the status result returned by the executed system command.

EXAMPLE:
    DOSCommand "delete c:\\temp\\foo.dat"
    DOSCommand ("copy " + source_file + " " + dest_folder)

    ShellLaunch <filename_string> <parameters_string>

ShellLaunch() emulates the double-clicking on a specified file in Windows.

Whatever you send to ShellLaunch will be run by the Windows shell automatically.

FOR EXAMPLE,
    ShellLaunch "E:\\tests\\lookup.html" ""
would launch the default Web Browser with lookup.html.

If a filenameextensionis not specified in <filename_string> , Windows will search the specified directory for executable files. If no directory is specified, Windows will search the paths in the Path environment variable for the executable file.

FOR EXAMPLE,
    shellLaunch "e:/program files/ucalc/ucalc" ""
will execute the ucalc.exe file in the specified directory.

The <parameters_string> is passed to the launched application as command line parameters.

FOR EXAMPLE,
    shellLaunch "e:/t.avi" "/play /loop"
will launch the application associated with .avi files, and pass /play and /loop as command line parameters.

Instead of launching a file with the default application registered for the given file type, the application to be launched can be passed as the first argument and the file to be opened as the second.This will pass the second argument as parameter to the application specified by the first argument.

FOR EXAMPLE,
    ShellLaunch "iexplorer.exe" @"c:\temp\report.html"
will launch the page report.html with the Internet Explorer,
    ShellLaunch "firefox.exe" @"c:\temp\report.html"
while the above will launch the same page in Mozilla Firefox.

The same approach can be used tonavigate to a specific path usingWindows Explorer.

FOR EXAMPLE,
    ShellLaunch @"c:\windows\" ""
    ShellLaunch "explorer.exe" @"c:\windows"
Both expressions will open Windows Explorer at the Windows root folder.
    ShellLaunch "explorer.exe" "/e,/select,\"c:\\windows\\notepad.exe\""
The above expression will open Windows Explorer at the file notepad.exe inside the Windows root directory.

    HiddenDOSCommand <command string to execute> [  startpath:unsupplied] [  prompt:unsupplied] [  donotwait:false] [  ExitCode:&variable]

[ AVG ] HiddenDOSCommand() looks like DOSCommand() , but runs more like ShellLaunch() . It launches a DOS command in a hidden window.

### startpath:

Allows you to set the starting folder for the command.

In versions prior to 3ds Max 2010, omitting this optional argument resulted in function failure. This has been corrected in 3ds Max 2010.

### prompt:

Allows you to set the prompt that appears on the Max prompt line (just below the viewports). If you don't change it, the command string is displayed.

### donotwait:

Allows you to decide whether or not you want to return control to back to MAXScript while the command runs, or wait for completion.Default is false, which results in blocking MAXScript execution until the command has finished.

### ExitCode:

If donotwait: is unsupplied or false and the command is executed successfully, the exit code of the command is written to the specified variable as an integer value.An exit code of 0 means the command was executed without errors, non-zero code usually means an error. Available in 3ds Max 2010 and higher.

Note

You must redirect any output generated to a file if you are interested in text that would normally be printed to the console.

EXAMPLE USAGE:
    HiddenDOSCommand "dir > %temp%\\hiddencmdout.tmp" startpath:"c:\\"
    cmd = "echo The time is " + localTime + " >> %temp%\\hiddencmdout.tmp"
    HiddenDOSCommand cmd startpath:"c:\\"
    HiddenDOSCommand "notepad %temp%\\hiddencmdout.tmp "prompt:"Waiting for Notepad to exit" startpath:"c:\\"
    HiddenDOSCommand "del hiddencmdout.tmp" donotwait:true startpath:"c:\\"
    makeDir "C:\\doscmdtest\\"
    str = "rmDir C:\\doscmdtest\\"
    hiddendoscommand str startpath:"$max" exitCode:&exitcode
    exitcode --> 0
    hiddendoscommand str startpath:"$max" exitCode:&exitcode
    exitcode --> 2 (error since directory does not exist anymore)
     --(Source for HiddenDOSCommand provided by Mike BiddleCombe)