Jump to content

Console Input & Output for Child Processes


DaveF
 Share

What functionality would be most the useful addition to AutoIt?  

17 members have voted

  1. 1. What functionality would be most the useful addition to AutoIt?

    • Just capture STDOUT and/or STDERR to a variable which would be accessible after Run() returned. Same behavior for Run() and RunWait().
      1
    • Same as above, plus a PresetStdin() function that allows you to preset a string that will be piped into the child process at Run() time.
      3
    • Run() starts the child process with open pipes to STDIN, STDOUT and STDERR. WriteStdin(), ReadStdout() and ReadStderr() interact with the child process. The child process is initially paused until a write to its STDIN is completed. ReadStdxxx() will pause until the child process writes something or closes the pipe. Not usable with RunWait().
      13
    • Other (please describe.)
      0


Recommended Posts

All entries assume adding Options to turn on the functionality.

What would you use?

If you choose choice 3 or choice 4 please provide an example of how it might be used.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

I belive the easiest for us would be to return a handle that could be used by the three functions. Maby an easier way to code would be to return an array of handles to be used by 'FileReadLine'.

An example of the latter could be:

$MysqlUser="someone"
$MysqlPassword="secret"
$size=0
Opt("RunReturnHandles",1)
$handles=run("ssh user@host.domain.com")
If IsArray($handles) then
    FileWriteLine($handles[1],"mysql -u "&$MysqlUser&" -p")
    FileWriteLine($handles[1],$MysqlPassword)
    do
        $line=FileReadLine($handles[0])
    until StringLeft($line,4)="Type"
    FileWriteLine($handles[1],"SELECT * FROM someDB.Sometable WHERE someField='something' LIMIT 10;")
    $DelimCount=0
    do
        $line=FileReadLine($handles[0])
        If $DelimCount=2 Then
            $fields=StringSplit($line,"|")
            If $fields[2]="needs backup" Then
                $BackupHandles=run("rsync -vae ssh "&$fields[3]&" user@host.domain.com:/somepath")
                do
                    $BackupLine=FileReadLine($BackupHandles[0])
                until StringInStr($BackupLine,"  speedup")>0
                $size=$size+StringMid($BackupLine,15,StringInStr($BackupLine,"  speedup")-15)
                FileClose($BackupHandles[0])
            EndIf
        EndIf
        If StringLeft($line,4)="+---" then $DelimCount=$DelimCount+1
    until $DelimCount>2
    FileClose($handles[0])
    MsgBox(0,"Backup",$size&" backed up")
Else
  ;failed to open
EndIf

This will not work, as it relies on the discussed code being implemented, and therefore hasn't been tested. Hopefully you can get an idea of what I was thinking of.

(BTW, I am writing this because I was asked

If you choose choice 3 or choice 4 please provide an example of how it might be used.

not to scratch an itch. Though now that I mention it....)

00110100010001110110111101100100

Link to comment
Share on other sites

For RunWait, I think that setting an input stream prior to and having the output retreived after the run could also be useful. set $STDIN, call RunWait, with $STDIN as a new argument, and then read @STDOUT or @STDERR. How does that sound?

David Nuttall
Nuttall Computer Consulting

An Aquarius born during the Age of Aquarius

AutoIt allows me to re-invent the wheel so much faster.

I'm off to write a wizard, a wonderful wizard of odd...

Link to comment
Share on other sites

Option 3 - This would be very useful (and probably the only solution) to control batch files. This would work in a similar way to the unix "expect" command. It would be possible to wait for a particular text output by the program, and then send some text back to the batch file (like Y or N or a filename, etc).

Of course it would be great if a "simple" mode that could be also used with RunWait was also implemented. It would allow to simply get the results of a command line program into a variable.

Cheers,

Angel

Link to comment
Share on other sites

Thanks for the thoughts.

Per the consensus, the tack that I'm taking is toward option 3 above, with AutoIt saving a collection of the handles that it cares about for each Run() process for as long as we're capturing, which can be called for / looked up by the PID result of the Run() function, e.g.

; Over-simple example
AutoitSetOption("CaptureStdio", 1)
$foo= Run("net.exe users", @SystemDir)
$bar = ReadStdout($foo)

This is more work than I had initially expected (brutal understatement).

I've got alpha code created for the read portion of the process, but my stream handles become unreadable after the storing and retrieval of my handle object; the handle is still valid and has the same value it did before it was stored, but any read procedure fails...

I'm using the correct security settings and making a non-inheritable duplicate of the handle I want to read, clsoing unused handles, etc.

I'll update when I figure it out.

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
Share on other sites

For RunWait, I think that setting an input stream prior to and having the output retreived after the run could also be useful.  set $STDIN, call RunWait, with $STDIN as a new argument, and then read @STDOUT or @STDERR.  How does that sound?

<{POST_SNAPBACK}>

Sounds fine, it would need adaptaion of the Sleep()-related process loop so that available data from the child process was read to insure that the child can close, but I need to do that anyway so that the ReadStdxxx() functions can have a timeout option...

Yes yes yes, there it was. Youth must go, ah yes. But youth is only being in a way like it might be an animal. No, it is not just being an animal so much as being like one of these malenky toys you viddy being sold in the streets, like little chellovecks made out of tin and with a spring inside and then a winding handle on the outside and you wind it up grrr grrr grrr and off it itties, like walking, O my brothers. But it itties in a straight line and bangs straight into things bang bang and it cannot help what it is doing. Being young is like being like one of these malenky machines.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...