Sign in to follow this  
Followers 0
t0ddie

STILL having problems with stdoutread

17 posts in this topic

#1 ·  Posted (edited)

so, if i do this, stdoutread freezes.

$Program="C:\Program Files\Diablo II\showcdkey.exe"
$Foo = Run ($Program)
    $line = StdoutRead($foo)

i close showcdkey.exe with the task manager and $line has no data.

but if i do this...

;script 1
run ("script2.exe")
$Program="C:\Program Files\Diablo II\showcdkey.exe"
$Foo = Run ($Program)
    $line = StdoutRead($foo)

;script 2
sleep(1000)
winclose("C:\Program Files\Diablo II\showcdkey.exe")

then $line has data.

and im not sure why, but i dont use the while loop and it captures every line in the prompt anyways. i tried with the while loop, and it still was freezing, so that wasnt the problem.

i want to do this using one script instead of 2, but i cant get it to work

i tried this...

$Program="C:\Program Files\Diablo II\showcdkey.exe"
$Foo = Run (@ComSpec & ' /c ' & $Program)
While 1
    $line = StdoutRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

it didnt freeze, but $line also had no data.

i had asked about this problem a few days ago, and im still trying to figure it out.

any help appreciated!

EDIT: typo

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites



WinClose

This function sends a close message to a window, the result depends on the window

I would guess it has to do with how the program is closed.


SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

right, but i cant get past stdoutread in the first script. the second script closes that prompt, and lets the first script continue.

i want it to run without freezing, and the only times it does that, it has no data.

it works fine with regular command prompts, like when you use comspec.

just not working with this program i have, "showcdkey.exe"

and i tried this

$Program="C:\Program Files\Diablo II\wdfo97t45ighergto9y7egfihkdfgkjh.exe"
$Foo = Run (@ComSpec & ' /c ' & $Program)
While 1
    $line = StdoutRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

flashes a black screen, so im not sure its even finding showcdkey.exe using this method because it will run anything you tell it to even a non existant file. and theres no error saying that the file cant be found.

so, im baffled.


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

if using release version try this:

; Demonstrates ReadStdout()
AutoItSetOption("ProvideRunStdout", 1)
AutoItSetOption("ProvideRunStderr", 1)
$Program='"C:\Program Files\Diablo II\showcdkey.exe"'
$foo = Run(@ComSpec & " /c " & $Program)

While 1
    $line = StdoutRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

MsgBox(0, "Debug", "Exiting...")

beta

#include <Constants.au3>

$Program='"C:\Program Files\Diablo II\showcdkey.exe"'
$foo = Run(@ComSpec & " /c " & $Program, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

While 1
    $line = StderrRead($foo)
    If @error = -1 Then ExitLoop
    MsgBox(0, "STDERR read:", $line)
Wend

MsgBox(0, "Debug", "Exiting...")

took a little time to find the showcdkey.exe for diablo, don't have the game but at least it gave me an error

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

i tried those first.. right from the help file.. if anyone had diablo ii and wants to help that would be great.

you dont even need the game, something just is not working. yeah if you run that program without the game installed you will get the error, but if the game is installed, the stdoutread still doesnt work unless you do it like i explained earlier.


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Can't you retrieve the cd key via the registry? Maybe it's only if your using Onlyer's cd key refiller with different .mpq names in the shortcut, if you know what I'm talking about.

Edit:

HKEY_CURRENT_USER\Software\Blizzard Entertainment\Diablo II
You can find your cdkey's.

Or you can redirect the output of showcdkey.exe to a txt file.

Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

if using release version try this:

There is no non-beta implementation of StdoutRead. Your first example is from the first beta implemenatation, gafrost...

So, t0ddie, thanks for providing the code you're having trouble with. If that's your actual code in the first post, then no, you're not going to get any output because you didn't specify in the call to Run that you care about the STDOUT handle.

Please use the most recent beta release and please read the beta manual entry for the StdoutRead function and the Run function, t0ddie, because you're wasting people's time.

Edited by DaveF

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

#9 ·  Posted (edited)

im not wasting anyones time... its your choice to spend your time in my post.

i can understand how you might assume that i wasnt using it correctly, but i just posted code that i typed quick, not copied and pasted from my script.

so im still having the problem. here is the code that i have that works, it uses 2 scripts.

script ONE

#include <Constants.au3>

$Program='"C:\Program Files\Diablo II\showcdkey.exe"'
$foo = Run(@ComSpec & " /c " & $Program, "", @SW_HIDE,$STDOUT_CHILD)
Run("close.exe")
$line = StdoutRead($foo)
MsgBox(0, "test", $line)

script TWO (close.exe)

sleep(1000)
WinClose(@comspec)

i DID leave some things out that i did not need. like i said, this script WORKS, but it uses 2 scripts, and i cant find a way to do it with one script.

if i dont close the prompt, stdoutread will just freeze until that window is closed.

closing the process returns no data, closing the window does.

ive tried many things.. adding subtracting things.. changing things around... so that may be why i posted code before that looked obviously wrong.

but anyways, if anyone could help tell me why this isnt working properly, it would be GREAT! i do appreciate the help and dont want to waste anyones time so if you are wasting your time here i urge you to please move on to more important people.

ty!

P.S.

and BURRUP

you cant retrieve the keys from the registry for the main install of the game.

the keys you are thinking of that can be retrieved are the extra keys you install with d2loader for playing multiple games. if i knew how the showcdkey.exe worked maybe i could recreate it myself, but im just using the program because i DONT know how to get the keys myself.

ty for your time

EDIT: hey burrup... how would i redirect the output to a text file??

Edited by t0ddie

Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks for clearing that up, I didn't want to reinstall D2 just to see if the keys were in the registry :">.

I just took maybe 30-45 minute break after writing the above sentence to come up with this :evil:, fully working.

#include <file.au3>

Dim $TempFile
$InstallDir = "C:\Program Files\Diablo II\"

$File = Run(@ComSpec & " /c title Get Diablo II Cdkey&&showcdkey.exe > " & _
            @TempDir & "\temp.txt", $InstallDir)

WinWaitActive("Get Diablo II Cdkey")
Send("{SPACE}")

While Not FileExists(@TempDir & "\temp.txt")
Wend

_FileReadToArray(@TempDir & "\temp.txt", $TempFile)
FileDelete (@TempDir & "\temp.txt")

$Owner = StringTrimLeft($TempFile[8], 13)
$Lod = StringTrimLeft($TempFile[9], 17)
$Classic = StringTrimLeft($TempFile[10], 13)

MsgBox(0,"Diablo II Cdkey's", "Owner:            " & $Owner & _
                              "LOD Cdkey:     " & $Lod & _
                              "Classic Cdkey:  " & $Classic)

My Story:

After a long experimentation period I found out I could not redirect the output to a file so easily. I began to wonder what was wrong, then I realised that the file wasn't being created until the command had finished. As you would know after running showcdkey.exe the command window display's "Press any key to continoue", after pressing a key the file is then created. I then began more experimentation with the "Press and key to continoue" subject, I came to the conclusion that for this to be passed you must press any key in the active cmd, meaning that you can't hide the window, nor can you trick it using the multiple command command string of "&&" which I tried, you have to do it manually, ie. Send("{SPACE"}), I chose spacebar because its the most logical option, it doesn't do anything to the cmd except, in this instance, close it :D. But how would I know when to press space bar? The time it takes the command to complete on different pc's may vary so I couldn't use a timer. I then done some poking in cmd /w "help" and found out I could change the title of the cmd window to whatever I wanted, ie. "Get Diablo II Cdkey". Using this new found info in combination with the conjuction string "&&" for cmd I was able to use WinWaitActive() to wait for the approiate time to send space bar.

The first problem was solved, redirecting the output to a file. I now began the quest of the second problem, retrieving the information from the file and displaying it. I knew to use _FileReadToArray() but how would I know when the file had been written to? I solved that with a quick While...Wend loop with nothing in it to get the fastest possible execution time. I then assigned $Owner, $LOD and $Classic with the retrieved information. To display the result's correctly I trimmed all the character from the left side of the string's only leaving the cdkey's/owner, some with a tad whitespace. I then whipped up a message box to display the result's and bobs your uncle.

Enjoy :)!

Edit: Looking at the time I replied, and the time you posted, it looks like it was 30-45 minuted but less lol, it seemed like forever but :D.

Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

i didn't know you guys played d2. If you guys are on USEast what's your account names :) sorry OT


My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

I began to wonder what was wrong, then I realised that the file wasn't being created until the command had finished. As you would know after running showcdkey.exe the command window display's "Press any key to continoue", after pressing a key the file is then created.

<{POST_SNAPBACK}>

Hmm. :)

no

<{POST_SNAPBACK}>

That was what I meant when I asked about input, t0ddie. Using the StdoutRead method you'd need to include the flag for STDIN in the call to Run and then StdinWrite a @CRLF (or anything) to simulate a keypress, then call StdinWrite a final time to close the STDIN pipe, then your child process would write the result and close.

Way to go, Burrup.


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

sorry bout the mixup, but the press any key to continue, that prompt comes up

AFTER the info is displayed and there is no user prompt until after that point.

but yeah, ty for looking at that for me, was really frustrating lol


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

Np, I like challenging myself :). I'll see if I can make an 'improved' version like what DaveF said using StdinWrite(), not much experience with StdXX() functions but I'll give it ago unless someone beats me to it :evil:


[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

i was gunna work on that myself, but i think you would beat me anyways so ill just wait.

i dunno how you would send data to the window though, because isnt it supposed to freeze with the stdoutread call?

well, i would love for this to be improved, thanks for your contribution!

im glad you decided to learn something new and help me at the same time!


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Interesting... After more experimentation I found out you could just simulate the keypress by closing the window :).

The below code will display exactly as it would if you opened up cmd and done it manually.

Enjoy!

#include <Constants.au3>

$InstallDir = "C:\Program Files\Diablo II\"

$Foo = Run(@ComSpec & " /c title Get Diablo II Cdkey&&showcdkey.exe", $InstallDir, @SW_HIDE, $STDOUT_CHILD)

WinWait("Get Diablo II Cdkey")
WinClose("Get Diablo II Cdkey")

MsgBox(0, "Diablo II Cdkey's", StdoutRead($Foo))
Edited by Burrup

[u]Old Projects:[/u]A3MORGB2Hex[u]Old Functions:[/u]_TimeAdd/_TimeSub_AddComma_BubbleSort _RippleSort "He who does not understand your silence will probably not understand your words." - Elbert Hubbard.

Share this post


Link to post
Share on other sites

i already knew that, but christ.. so simple.. just close the window BEFORE the stdoutread!

i didnt know that it could read it while its not open, but now that i think about it.. its saved as $foo

brilliant.


Valik Note Added 19 October 2006 - 08:38 AMAdded to warn level I just plain don't like you.

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