ExecuteBatchFile()

Function to execute a command line statement. The function creates a batch file and runs the code that is provided. Execution of the script can be halted while the batch file executes.

The batch file is created in the directory of the current project. When the batch file is done, the batch file is deleted. When there is no current project, the batch file is created in C:\. This function does not check for write permissions on C:\.

Note: The script automatically adds a line to the batch file that deletes the batch file after the batch file has run. When the batch file is not deleted, the function will halt the script indefinitely if the functions waits for the batch file to execute.

The method ExecuteBatchFile() is located in the file cmd.jsxinc.

Usage

To execute a batch file and wait for the batch file to execute:

var batch = "del C:/myfile2.txt\n";
batch += "rename C:/myfile.txt C:/myfile2.txt";
ExecuteBatchFile(batch);

To execute a batch file while not waiting for the batch file to execute:

var batch = "del C:/myfile2.txt\n";
batch += "rename C:/myfile.txt C:/myfile2.txt";
ExecuteBatchFile(batch, false);

Note: If you want to use multiple batch commands, you need to put each command on a new line. You create a new line by adding \n to your string.

 

Parameters

Parameter Data type Required Description
command String The command to execute. Add multiple commands by adding a line break (\n) to the end of each line for the batch file.
waitforbatch Boolean   If set to false, the script will not wait for the batch file to execute. Default is true.

Return values

Value Meaning
false Could not execute command.
true Command executed. Errors that occurred during batch execution are ignored.