Execute
This method allows you to execute any command from within a script.
It takes a ExecuteArgs as the only parameter
ExecuteArgs
Name | Description | Type | Example |
---|---|---|---|
command | The name of the command to execute | string | ffmpeg |
arguments | The arguments to pass to the command | string | -i file.mkv -o out.mp4 |
argumentList | Same as arguments but a string array | string[] | ['-i', 'file.mkv', '-o', 'out.mp4'] |
timeout | Optional: The timeout of this command in seconds | number | `30`` |
workingDirectory | Optional: The working directory to execute the command in | string | /media/my/folder |
info
Only use one of arguments
and argumentList
, do not use both
ExecuteArgs C# Object
If you wish to use the strongly typed ExecuteArgs
objects, you need to use TitleCasing
and you have more properties.
Name | Description | Type | Example |
---|---|---|---|
Command | The name of the command to execute | string | ffmpeg |
Arguments | The arguments to pass to the command | string | -i file.mkv -o out.mp4 |
ArgumentList | Same as arguments but a string array | string[] | ['-i', 'file.mkv', '-o', 'out.mp4'] |
Timeout | Optional: The timeout of this command in seconds | number | `30`` |
WorkingDirectory | Optional: The working directory to execute the command in | string | /media/my/folder |
add_Output | Function with single parameter of each output line as it is received | function | function(string line) |
add_Error | Function with single parameter of each error line as it is received | function | function(string line) |
Output
Name | Description | Type | Example |
---|---|---|---|
completed | If the command completed or not | boolean | true |
exitCode | The exit code of the command | number | 0 |
output | The output from the command | string | output |
standardOutput | The standard output from the command | string | some standard output |
standardError | The error output from the command | string | Error: something went wrong |
Example
Calling FFmpeg
// define the output file, in the temp directory with a guid as the name
let output = Flow.TempPath + '/' + Flow.NewGuid() + '.mkv';
// get the ffmpeg tool path
let ffmpeg = Flow.GetToolPath('ffmpeg');
// execute the process and capture the result
let process = Flow.Execute({
command: ffmpeg,
workingDirectory: '/media/my-working/directory',
argumentList: [
'-i',
Variables.file.FullName,
'-c:v',
'libx265',
'-c:a',
'copy',
output
]
});
// log the standard output/error if found
if(process.standardOutput)
Logger.ILog('Standard output: ' + process.standardOutput);
if(process.starndardError)
Logger.ILog('Standard error: ' + process.starndardError);
// check the exit code of the process
if(process.exitCode !== 0){
Logger.ELog('Failed processing ffmpeg: ' + process.exitCode);
return -1;
}
// update the working file to the newly created file from ffmpeg
Flow.SetWorkingFile(output);
return 1;
Calling with Output
This examples shows how to process the output from the execute command as it is received, this allows you to do progress updates by parsing the output.
var executeArgs = new ExecuteArgs();
executeArgs.Command = 'ping';
executeArgs.ArgumentList = [
'-c',
'2',
'8.8.8.8'
];
// Set up the callback output
let standardError = false;
let standardOutput = false;
executeArgs.add_Output((line) => {
Logger.ILog("Standard Output: " + line);
standardOutput = true;
});
executeArgs.add_Error((line) => {
Logger.ILog("Error Output: " + line);
standardError = true;
});
Flow.Execute(executeArgs);
Logger.ILog('standardOutput: ' + standardOutput);
Logger.ILog('standardError: ' + standardError);
return standardOutput || standardError ? 1 : 2;
";