User Tools

Site Tools


Sidebar

command-line:executebatchfile

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.

Instead of this function, you can also use RoboHelp.executeCommandline. This function precedes the method in RoboHelp and is retained for backwards compatibility. The library itself uses ExecuteBatchFile() to stay compatible with older RoboHelp versions.

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:\ProgramData.

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

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 Yes 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
true Command executed. Errors that occurred during batch execution are ignored
false Could not execute command
command-line/executebatchfile.txt · Last modified: 2017/05/20 13:24 (external edit)