Skip to main content

Execute

This method allows you to execute any command from within a script.

It takes a ExecuteArgs as the only parameter

ExecuteArgs

NameDescriptionTypeExample
commandThe name of the command to executestringffmpeg
argumentsThe arguments to pass to the commandstring-i file.mkv -o out.mp4
argumentListSame as arguments but a string arraystring[]['-i', 'file.mkv', '-o', 'out.mp4']
timeoutOptional: The timeout of this command in secondsnumber`30``
workingDirectoryOptional: The working directory to execute the command instring/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.

NameDescriptionTypeExample
CommandThe name of the command to executestringffmpeg
ArgumentsThe arguments to pass to the commandstring-i file.mkv -o out.mp4
ArgumentListSame as arguments but a string arraystring[]['-i', 'file.mkv', '-o', 'out.mp4']
TimeoutOptional: The timeout of this command in secondsnumber`30``
WorkingDirectoryOptional: The working directory to execute the command instring/media/my/folder
add_OutputFunction with single parameter of each output line as it is receivedfunctionfunction(string line)
add_ErrorFunction with single parameter of each error line as it is receivedfunctionfunction(string line)

Output

NameDescriptionTypeExample
completedIf the command completed or notbooleantrue
exitCodeThe exit code of the commandnumber0
outputThe output from the commandstringoutput
standardOutputThe standard output from the commandstringsome standard output
standardErrorThe error output from the commandstringError: 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;
";