Skip to content

RunCapture (run and capture output)

ts
function RunCapture(commandLine: string): string;

NOTE

This function is available as of Syncplify Server! v7.1.1. If you are running an older version, upgrade to v7.1.1 or later to use it.

Executes an external program synchronously and returns its combined standard output and standard error as a single string. This is useful when your script needs to act on the text produced by an external tool rather than only knowing whether it succeeded.

Unlike Run, RunCapture does not indicate the process exit code: it always returns whatever text was written to stdout or stderr, even if the process exited with an error. If the process cannot be started at all, an empty string is returned.

ParameterTypeRequirementExplanation
commandLinestringrequiredThe command to execute, exactly as you would type it in a shell
Return valueExplanation
stringCombined stdout and stderr output of the process
""The process could not be started

NOTE

RunCapture waits for the process to exit before returning. For long-running processes that should run in the background, use RunAsync instead.

Examples

Parse the output of a system command

ts
var output = RunCapture('df -h /var');
Log('Disk usage:\n' + output);

Capture a checksum tool's output

ts
var result = RunCapture('md5sum /var/outbox/delivery.zip');
var hash = result.split(' ')[0];
Log('MD5: ' + hash);

Conditional logic based on output content

ts
var out = RunCapture('/usr/local/bin/check-service status');
if (out.indexOf('running') >= 0) {
  Log('Service is running.');
} else {
  Log('Service may be down: ' + out);
}