Sign in to follow this  
Followers 0
987learner

How to pipe a console tool output to autoit as input

17 posts in this topic

Does anyone have any links that can throw some light (any tutorial/explanation) how to pipe any console tool's output and let autoit receive as input?

Thanks in advance

Share this post


Link to post
Share on other sites



Ok, will look at the help file for this function

BTW, the example given in helpfile #include <Constants.au3> is it necessary? When can we omit this syntax?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Instead of #include <Constants.au3>; You can use the numerical values.

[optional] Provide a meaningful handle to one or more STD I/O streams of the child process.
  1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream
  2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream
  4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream
  8 ($STDERR_MERGED) = Provides the same handle for STDOUT and STDERR. Implies both $STDOUT_CHILD and $STDERR_CHILD.
Edited by AzKay

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

I'm tried a console tool (MD5.exe) to pipe to autoit. Got blank input. What is wrong with my code?

#include <Constants.au3>
local $Filename
local $MD5CLI=Run (@ComSpec & " /c md5 "& $FIlename, @ProgramFilesDir&"\Windows Media Player", @SW_HIDE, 2)

$Filename="C:\Program Files\Windows Media Player\wmplayer.exe"
; Actual MD5 is : 9F40532B1F0424297188E6E48BFB90F8

$MD5CLI=Run (@ComSpec & " /c md5 "& $FIlename, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
$line = StdoutRead ($MD5CLI)
msgbox (0,"StdoutRead ",StdoutRead ($MD5CLI)); <--- blank output. Where goes wrong in my code?

Share this post


Link to post
Share on other sites

Try this udf by lod3n.

Share this post


Link to post
Share on other sites

I'm tried a console tool (MD5.exe) to pipe to autoit. Got blank input. What is wrong with my code?

#include <Constants.au3>
local $Filename
local $MD5CLI=Run (@ComSpec & " /c md5 "& $FIlename, @ProgramFilesDir&"\Windows Media Player", @SW_HIDE, 2)

$Filename="C:\Program Files\Windows Media Player\wmplayer.exe"
; Actual MD5 is : 9F40532B1F0424297188E6E48BFB90F8

$MD5CLI=Run (@ComSpec & " /c md5 "& $FIlename, @ScriptDir, @SW_HIDE, $STDOUT_CHILD)
$line = StdoutRead ($MD5CLI)
msgbox (0,"StdoutRead ",StdoutRead ($MD5CLI)); <--- blank output. Where goes wrong in my code?
Try;

While 1
$line = StdoutRead($MD5CLI)
If $line <> "" Then ConsoleWrite($line & @CRLF)
WEnd

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Try this udf by lod3n.

How to use udf?

Also can look at my code and see if it can be modify to make it work? I wish to learn from my own experiement too.

Share this post


Link to post
Share on other sites

How to use udf?

Also can look at my code and see if it can be modify to make it work? I wish to learn from my own experiement too.

Well, Did you try what I suggested?

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

I dun know to to write using udf... sorry.

Share this post


Link to post
Share on other sites

How to use udf?

There are examples in the post.

Share this post


Link to post
Share on other sites

I dun know to to write using udf... sorry.

I didnt suggest using a UDF. I gave you a loop to put in your code.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

I didnt suggest using a UDF. I gave you a loop to put in your code.

Ok, I missed it earlier. Now testing again, seems to work but unable to display result in the msgbox.

I can see the result in output (F8) but the script is in endless loop state. It is unable to end normally.

#include <Constants.au3>
local $Filename, $line
local $MD5CLI=Run (@ComSpec & " /c md5 "& $Filename, @ScriptDir, @SW_HIDE, 2)

$Filename="C:\Program Files\Windows Media Player\wmplayer.exe"
; MD5: 48CDAB5EB8C952534AE2C5AED72CCB70

$MD5CLI=Run (@ComSpec & " /c md5 "& $Filename, @ScriptDir, @SW_HIDE, 2)
While 1
$line = StdoutRead($MD5CLI)
If $line <> "" Then ConsoleWrite($line & @CRLF)
WEnd
msgbox (0,"StdoutRead ",$line)

Share this post


Link to post
Share on other sites

The reason the loop works, and not the messagebox, because StdoutRead gives you the "current" sdout text, so if you call it just once, youll more or less always get a blank line.

Just add error checking in the loop, like; $line = stdoutread($md4cli); If not @error and $line <> "" then msgbox, else exitloop. Or something.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#include <Constants.au3>

; Tell AutoIt ahead-of-time the variable names we'll use
Dim $Filename, $line, $MD5CLI

$Filename="C:\Program Files\Windows Media Player\wmplayer.exe"
; MD5: 48CDAB5EB8C952534AE2C5AED72CCB70

; MD5.EXE is copied to the same folder as the script file for this example
; MD5.EXE could have been anywhere as long as we used the full path
$MD5CLI=Run (@ScriptDir & "\md5.exe "& $Filename, @ScriptDir, @SW_HIDE, 2)

While 1
  ; Try to read any output from MD5.EXE
  ; StdoutRead will assign a value to the macro variable @error
  ; if MD5.EXE signals that there's no more to read.
  ; Using &= below means to add what is read from StdoutRead
  ; to anything that we've read previously and store in $line
  ; We must always use a loop with StdoutRead because there's
  ; no guarantee that the child program writes output in full lines.
  ;     \/
  $line &= StdoutRead($MD5CLI)
  If @error Then ExitLoop
  ; If we're here assume that there's more to read, go back and loop again
WEnd

msgbox (0,"StdoutRead ",$line)


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.

Share this post


Link to post
Share on other sites

Thanks, DaveF & AzKay for assisting, finally got it.

Apparently, the example script in help file doesn't use '&='. It uses '=' . (Perhaps can add some of these details in future revision).

Thanks again.

Share this post


Link to post
Share on other sites

Using &= is the same as doing $line = $line & $line. Basically; To show it all at once, after the loop.

The helpfile example; uses $line =, Because it shows the info straight away, not once the programs ended.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

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