Core Function RunCapture

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
m (1 revision)
 
(2 intermediate revisions by one user not shown)
Line 65: Line 65:
  
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
$value = Trim(qx(echo cat)[1]);
+
$value = Trim(qx(echo cat));
 
echo "Value is $value\n";
 
echo "Value is $value\n";
 
// Prints
 
// Prints
Line 75: Line 75:
 
<syntaxhighlight lang="sputnik">
 
<syntaxhighlight lang="sputnik">
 
$t = "cat";
 
$t = "cat";
$value = Trim(qqx(echo $t)[1]);
+
$value = Trim(qqx(echo $t));
 
echo "Value is $value\n";
 
echo "Value is $value\n";
 
// Prints
 
// Prints

Latest revision as of 12:37, 14 June 2015

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