Jump to content

Grabbing Output From A Command Line Program


Recommended Posts

I have an md5 summer program that is .exe and it outputs to the command prompt the info I need. How do I execute it and grab its output? Or does anyone know of a .dll package I could use more directly.

Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Link to comment
Share on other sites

Look for StdOutRead in the help file.

Edit - Needs Beta

Edited by BigDod


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Hmm... this does not seem to be working... I believe it is because if the program takes longer then expected, my script skips the output and move on, the RunWait command does not have the $STDERR_CHILD + $STDOUT_CHILD options. It starts out working fine, but its md5ing very small files. The first file that takes more then a few milliseconds its out of sync and doesnt show output again. It through a list of files and sends each one individually to the md5 program.

Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Link to comment
Share on other sites

Hmm... that would be too slow, im going through a list of files > 100 and attempting to calculate the md5 hash. I recon im going to have to do it in some other language.

Ooo Ëxçã¿îbúr ooO"Information Is Not Knowledge." ~Albert Einstein
Link to comment
Share on other sites

Hmm... this does not seem to be working... I believe it is because if the program takes longer then expected, my script skips the output and move on, the RunWait command does not have the $STDERR_CHILD + $STDOUT_CHILD options. It starts out working fine, but its md5ing very small files. The first file that takes more then a few milliseconds its out of sync and doesnt show output again. It through a list of files and sends each one individually to the md5 program.

By default StdxxRead waits as long as it needs to to read some data, but it accepts any single write operation and returns at that point without waiting for further output; I don't know anything about your hash generator but it could be writing something like a single linfeed on the first write so that you get no apparent output. The average script has a loop that reads until the child program closes the pipe (at which point StdxxxRead sets @error to -1) then continues execution.

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 have an md5 summer program that is .exe and it outputs to the command prompt the info I need. How do I execute it and grab its output? Or does anyone know of a .dll package I could use more directly.

Okay, I looked at the newest beta help and the example for stdchild doesn't seem to be there any more. In any case, you need to use syntax similar to the following, in order to give the program time to finish collecting all of the output from your command prompt process:
#include <constants.au3>
#include <guiconstants.au3>
dim $out
$pid = run(@comspec & ' /c dir c:\temp',@TempDir,"",$stdout_child) 
While 1
        $out &= StdoutRead($pid)
        If @error = -1 Then ExitLoop
        MsgBox(0, "STDOUT read from inside the loop:", $out)
Wend  
        MsgBox(1,"the complete output",$out)

Notice what the two separate message boxes put out. The one inside the loop gets the output a piece at a time. The one outside the loop displays the final tally.

Now, despite how this seems to work, I have frequently had trouble with stdout in cases where the output was slow in coming or where it was a large amount of output. DaveF and I have tried to trouble shoot this, but my examples are so arcane that it's tough for him to replicate the context.

If all else fails, what I do is use a clipboard utility called clipboard.exe that grabs the output of my function and stuffs it into the clipboard (memory). I then grab what's in the clipboard using clipget() and parse that as needed. This method always works. How fast it is compared to using intermediary text files is unknown, but I believe it should be faster since it doesn't require opening and writing to the hard disk. You can find clipboard at Synesis software: http://www.synesis.com.au/systools.html

The syntax I use looks something like this:

run(@comspec & ' /c ' & "myprogram" & " | clipboard.exe",@tempdir)
$output = clipget()
...do something to $output...

Code not tested, just ottomh

...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
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...