Sign in to follow this  
Followers 0
abhi

Reading Streams of Child Process

8 posts in this topic

Hi,

I want to be able to read streams spat out by child process. Following was my approach to invoke child process

....

RunAsSet($var1,$var2,$var3)

if @error Then

FileWrite($logFile, "Error executing script. Please check if the user and password are valid.")

FileClose($logFile)

Exit 1

EndIf

Run($var4)

......

Presently, Streams of child processes run with RunAsSet cannot be read and hence I am unable to capture the output of the child process I am invoking.

Running the child process using RunAsSet() is paramount to me and I cannot do without it. Can anybody suggest a work around to achieve my objective of capturing child process output.

Thanks

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

RunAsSet($var1,$var2,$var3)
$pid=Run($var4,"","",2)
$read=StdoutRead ($pid)

Somting like so? or that doesn't work?

Edited by evilertoaster

Share this post


Link to post
Share on other sites

RunAsSet($var1,$var2,$var3)
$pid=Run($var4,"","",2)
$read=StdoutRead ($pid)

Somting like so? or that doesn't work?

That doesn't work.

Share this post


Link to post
Share on other sites

Well this is an idea - not tested in any way....

If you run your script as the administrator - would you need to use RunAsSet ???

From JdeB's homepage http://www.autoitscript.com/fileman/users/jdeb/jdeb_autoit_stuff.htm

; AutoIt Version: 3.0
; Language:       English
; Platform:       Win9x/NT/XP
; Author:         jos van der Zande
;
AutoItSetOption("RunErrorsFatal", 0) 
AutoItSetOption("TrayIconHide", 1) 
Break(0)
$USERNAME = "Administrator"
$PASSWORD = "Secret"
$RUN = 0       ; run indicator 
; retrieve the cycle from commandline
If $CMDLINE[0] = 1 Then $RUN = $CMDLINE[1]
If $RUN = 0 Then
   RunAsSet($USERNAME, @ComputerName, $PASSWORD)
   Run('"' & @ScriptFullPath & '" " 1"') 
   If @error Then MsgBox(4096+32,"Error", "Error starting under admin mode")
   Exit
EndIf
; commands go here that require Administrator rights

Start here if you are new Valuater's AutoIT 1-2-3Looking for an UDF - Look hereDo you need to do it twice - Autoit

Share this post


Link to post
Share on other sites

Why not make a StreamRunner.exe which you call from your main Exe with RunAsSet. Then, StreamRunner.exe runs your child processes under that security context, and records the streams. It then writes the streams to an intermediate file, which is read by your main exe when StreamRunner finishes.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Why not make a StreamRunner.exe which you call from your main Exe with RunAsSet. Then, StreamRunner.exe runs your child processes under that security context, and records the streams. It then writes the streams to an intermediate file, which is read by your main exe when StreamRunner finishes.

I tried your approach. I don't think the subsequent Run() (called from the exe that is streaming out put) is being executed under the security context established by the main executables RunAsSet() call.

I was able to prove that based on a test, where I sent in incorrect password to my main exe.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

is to required to have communication this way only? or could you use somthing simple like writing to a file or registry key?

Edited by evilertoaster

Share this post


Link to post
Share on other sites

Really? It works for me. Try this. StreamRunner.exe:

#include <Constants.au3>
$foo = Run(@ComSpec & " /c echo %username%", @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
$output = ""
While 1
    $output &= StdoutRead($foo)
    If @error Then ExitLoop
Wend
FileDelete(@scriptdir&"\stdout.txt")
FileWrite(@scriptdir&"\stdout.txt",$output)oÝ÷ Ø Ý¶¦j)ÞÅ殶­se'Vä56WBgV÷C´FÖæ7G&F÷"gV÷C²Â6ö×WFW&æÖRÂgV÷C¶FÖç72gV÷C²¥'VåvBgV÷C·7G&'VææW"æWRgV÷C²¥'Vä56WB ¢b33c¶÷WGWBÒfÆU&VB67&FF"fײgV÷C²b3#·7FF÷WBçGBgV÷C²¤×6v&÷ÂgV÷Cµ7FF÷WBg&öÒ7G&VÕ'VææW"gV÷C²Âb33c¶÷WGWB

When I run this, it reports back the username I set with RunAsSet, not the username I logged on the the computer with.


[font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0