Core Function RunCapture

From Sputnik Wiki
Jump to: navigation, search
RunCapture( <file>, <arguments>, <workdir>, <flag>, <function> )

Contents

Description

Run a program in a hidden window and capture its printed output as strings.

Parameters

file

The name of the executable (EXE, BAT, COM, or PIF) to run.

arguments

The arguments to use.

workdir

The working directory.

flag

The "show" flag of the executed program:

@SW_HIDE = Hidden window
@SW_MINIMIZE = Minimized window
@SW_MAXIMIZE = Maximized window

Default runs the program normally.

function

A string to parse and execute as Sputnik code (usually a function call)

Return Value

Success: The PID of the process that was launched.

Failure: 0.

Remarks

After running the requested program the script continues and you probably wont get any captured information.

You should create a loop to watch and wait for the process to end and use DoEvents so you can capture all the text see example below.

Example

my $PID = RunCapture(@SYSDIR . @"\ping.exe", "www.yahoo.com", "", @SW_HIDE, 'Capture($arg);');
while(ProcessExists($PID))
{
	DoEvents();
}
Function Capture( $arg )
{
	println("Captured: " . $arg);
}

You can also use the qx() operator

$value = Trim(qx(echo cat));
echo "Value is $value\n";
// Prints
// Value is cat

You can also use the qqx() operator

$t = "cat";
$value = Trim(qqx(echo $t));
echo "Value is $value\n";
// Prints
// Value is cat
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox