Go to: Synopsis. Return value. Related. MEL examples.

Synopsis

system string

system is NOT undoable, NOT queryable, and NOT editable.

The string argument is a command which gets executed from the shell. The output of the executed command is returned as a string. Note that the system command is system dependent, and will give different results on Windows than on a UNIX system. Special Notes: To run a command in the background on Linux, you must redirect its output. e.g.:
system("sleep 10 >/dev/null 2>&1 &");

Naturally, you can send output to somewhere other than /dev/null if you like. To run a command in the background on Windows, use either the "start", "shell", or "load" command. The only difference between the "start" and "shell" is that "shell" uses the command processor, so the built-in commands (e.g. DIR, COPY) will be available.
e.g.:
system("start C:/aw/Maya/bin/fcheck.exe " + $filename);

"load" is another keyword available on Windows. Using the "load" keyword followed by a filename causes Windows to attempt to find the default application for that type of file. The file is then opened with that application as a background task. If you use the "start" command, a command process window will pop up in Windows and the MEL function that system is called from will wait until the process is complete before continuing. If you are attempting to hide this pop up window, in some cases you may not want to use the "shell" command. If you use the "shell" command, the command window will be hidden and the process will run in the background, but the MEL function that "system" was called from will continue running, and will not wait for the process to complete. This may cause problems if you are relying on the completion of the system function before continuing on in the calling MEL Script. The solution is to simply call system with no "start" or "shell" extra command.
e.g.:
system("C:/aw/Maya/bin/fcheck.exe " + $filename);

This will run the process silently so a window does not pop up, and it will also run the process in the foreground, so the calling MEL Script waits until the process is complete before continuing.

Return value

string Result of execution

Related

exec, pclose, popen

MEL examples

// On Linux
//
system("/usr/bin/date");
// Result: Tue Nov 23 18:12:39 EST 1999
//

// On Windows
//
system("start C:/WINNT/NOTEPAD.EXE" );

$directoryListing = system("DIR");

// Make a sample file to use as a test example
//
$exampleFileName = ( `internalVar -userTmpDir` + "example.txt" );
$fileId=`fopen $exampleFileName "w"`;
fprint $fileId "Hello there\n";
fclose $fileId;

// Use the "load" keyword to open the file with the default app.
// (Windows only)
//
system("load " + $exampleFileName );