Jump to content
Sign in to follow this  
Ravi1stop

Reading from a child process

Recommended Posts

Ravi1stop

I am launching an interactive session with an application using the run command. The application stays active till the exit command is given. I can see the responses from the application in the debug window but cannot figure out how to get that data into the code so that I can detect that the process has been completed. here is the code

#include <constants.au3>

global $fname
$fname="11-6-11"

Run("c:program files3d3solutionsflexscan3d 3flexscan3d.exe interactive ","","",$STDIN_CHILD())
sleep(10000)
Global $PID = ProcessExists("Flexscan3d.exe")

StdinWrite($PID,'scriptline set("Scanning_WidePhase_Enabled","True") n'&@CRLF)
sleep(2000)
StdinWrite($PID,"scriptline scan() n" &@CRLF)

sleep(5000)


StdinWrite($PID,"exit" &@CRLF)
 

Here is the output:
>Running:(3.3.8.1):C:Program Files (x86)AutoIt3autoit3.exe "C:UsersNew AdministratorDesktopscriptflexscan.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
:interactive
<< scriptline set("Scanning_WidePhase_Enabled","True") n
>> :done scriptline set("Scanning_WidePhase_Enabled","True") n
<< scriptline scan() n
>> :done scriptline scan() n
+>14:39:30 AutoIt3.exe ended.rc:0
>Exit code: 0    Time: 18.978

 

Rather than use the sleep function and hope the process gets done in time, I would like to wait till the process is actually complete.

Thanks

Share this post


Link to post
Share on other sites
martin

I think you need to look up StdoutRead in the help.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Ravi1stop

My apologies for being relatively new at this. I did try the Stdoutread the best I could looking at the limited examples from the forum with not much success. There are not a lot of examples for it and my programming skills are unfortunately not very good. Appreciate any assistance or guidance.

Thanks

Share this post


Link to post
Share on other sites
martin

It doesn't matter if you get it wrong, but the help for stdoutread has an example, so could you try applying that then tell us what, if anything happens and then we can build from there.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites
Chimp

Hi Ravi1stop

to catch the output from a dos program you have to run it with the $STDOUT_CHILD parameter and then use StdoutRead() to get the output

>here I posted some examples

Bye


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
Ravi1stop

Thank you I have it figured out now. May not be the best code but it works.

 

#include <constants.au3>

global $fname
$fname="11-6-11"

Run("c:program files3d3solutionsflexscan3d 3flexscan3d.exe interactive ","","",$STDIN_CHILD()+ $STDOUT_CHILD())

Global $PID = ProcessExists("Flexscan3d.exe")
check_std()
StdinWrite($PID,'scriptline set("Scanning_WidePhase_Enabled","True") n'&@CRLF)
check_start()
check_end()
;sleep(2000)
StdinWrite($PID,"scriptline scan() n" &@CRLF)
check_start()
;sleep(5000)
check_end()


StdinWrite($PID,"exit" &@CRLF)

Func check_std()
    Local $line

while 1
    $line = StdoutRead($PID)
    if StringLen($line)> 8 then ExitLoop
WEnd
EndFunc
Func check_start()
    Local $line2

while 1
    $line2 = StdoutRead($PID)
    if StringLen($line2) > 10 then ExitLoop
WEnd
EndFunc
Func check_end()
    Local $line2

while 1
    $line2 = StdoutRead($PID)
    if StringLeft($line2, 8) = ">> :done" then ExitLoop
WEnd
EndFunc

; Finished!
 

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  

×