Core Function RunCapture
From Sputnik Wiki
(Difference between revisions)
(Created page with "<pre> RunCapture( <file>, <arguments>, <workdir>, <flag>, <function> ) </pre> === Description === Run a program in a hidden window and capture its printed output as strings. =...") |
(→Example) |
||
Line 60: | Line 60: | ||
println("Captured: " . $arg); | println("Captured: " . $arg); | ||
} | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | You can also use the qx() operator | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $value = Trim(qx(echo cat)[1]); | ||
+ | echo "Value is $value\n"; | ||
+ | // Prints | ||
+ | // Value is cat | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | You can also use the qqx() operator | ||
+ | |||
+ | <syntaxhighlight lang="sputnik"> | ||
+ | $t = "cat"; | ||
+ | $value = Trim(qqx(echo $t)[1]); | ||
+ | echo "Value is $value\n"; | ||
+ | // Prints | ||
+ | // Value is cat | ||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Core Function]] | [[Category:Core Function]] |
Revision as of 01:29, 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)[1]); echo "Value is $value\n"; // Prints // Value is cat
You can also use the qqx() operator
$t = "cat"; $value = Trim(qqx(echo $t)[1]); echo "Value is $value\n"; // Prints // Value is cat