Core Function RunCapture
From Sputnik Wiki
(Difference between revisions)
(→Example) |
(→Example) |
||
Line 65: | Line 65: | ||
<syntaxhighlight lang="sputnik"> | <syntaxhighlight lang="sputnik"> | ||
− | $value = Trim(qx(echo cat) | + | $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) | + | $value = Trim(qqx(echo $t)); |
echo "Value is $value\n"; | echo "Value is $value\n"; | ||
// Prints | // Prints |
Revision as of 01:40, 14 September 2013
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