javip Posted September 12, 2012 Share Posted September 12, 2012 (edited) I have a combo box system I'm writing, and depending on which combo index is selected, a different set ofcommands is run.i usually use sleep in between comspec commands.the real issue is that only the final $cmd variable is running, not the ones before.i tried resetting the variable to nothing using $cmd = 0.all the stdout functions are there because i'm using it as feedback into an editbox.that part works perfectly.i'm sure that i i'm implementing the variable part wrong in the way i want it to work.i'm passing the ipconfig and netsh commands just for feedback.so in this example the netsh command is being the only on being run and sending its output to the editbox.thanks everyone.here's the code:Func selection() $sSel = GUICtrlRead($cb_platform) $iIndex = _ArraySearch($aList, $sSel) Select Case $iIndex = 0 MsgBox(1, "test","test?") $cmd = Run(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $cmd = 0 Sleep(2000) $cmd = Run(@ComSpec & " /c netsh /?", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Case $iIndex = 1 MsgBox(1, "test2", "test2") Case $iIndex = 2 MsgBox(1, "test3", "test3") EndSelect EndFunc Edited September 12, 2012 by pixeldotz Link to comment Share on other sites More sharing options...
BrewManNH Posted September 12, 2012 Share Posted September 12, 2012 How are you determining that only the final Run command is running? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 12, 2012 Moderators Share Posted September 12, 2012 Hi, pixeldotz. Just out of curiosity, why are you assigning the same variable name to two different Run statements? I would use one variable name for your IPConfig, and another for your Netsh, so they're not stepping on each other. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
javip Posted September 12, 2012 Author Share Posted September 12, 2012 (edited) How are you determining that only the final Run command is running? BrewManNH: It wasn't running the command I had in there originally which was a drvload command. However, I just tried it using NOTEPAD instead of ipconfig and it launched notepad. it ran the netsh command. so it looks like it is running one command after another, just populating the editbox with the last command ran stdout. thanks for pointing that out - i don't know why you asking that question prompted me to check a more 'visual' method ie. using notepad. using RunWAIT ran netsh after i closed notepad. RunWait might be the right way to go but no feedback except for the final command. Hi, pixeldotz. Just out of curiosity, why are you assigning the same variable name to two different Run statements? I would use one variable name for your IPConfig, and another for your Netsh, so they're not stepping on each other. JLogan: two reasons. i couldn't get this to run with multiple variables: $data = StdoutRead($cmd) If $data Then GUICtrlSetData($hEdit, $data, 1) EndIf this is how i'm populating the editbox with the stdout feedback. second reason is that since it's running the commands sequentially it didn't seem to be an issue. so i guess my real question would be why is only the final command putting stdout to the editbox instead of one command after another? thank you both for the replies. Edited September 12, 2012 by pixeldotz Link to comment Share on other sites More sharing options...
BrewManNH Posted September 12, 2012 Share Posted September 12, 2012 That's why you're not getting the output from the first program run, you reuse the variable that holds the PID for it and overwrite it with the second program run. You can only read the StdOut using the PID, and the first PID isn't recorded. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
javip Posted September 12, 2012 Author Share Posted September 12, 2012 (edited) shouldn't it clear with each command run? it's running ipconfig, then ipconfig should put it's STDOUT to the editbox, then the next $cmd runs and that clears the previous one like you said. but in this case the first one isn't getting used at all. i understand what you're saying that this is the wrong way to do this but i don't understand why the previous $cmd would not record anything. from searching on the forums and around the net it seemed that reusing the variable wouldn't be an issue, it should just destroy itself after each use. Edited September 12, 2012 by pixeldotz Link to comment Share on other sites More sharing options...
BrewManNH Posted September 12, 2012 Share Posted September 12, 2012 Run this script in SciTE and observe the console output. Then change the variable $PID2 to $PID1 in the Run line and the StdOutRead line, and see what you get in the console. $PID1 = Run(@ComSpec & " /c dir C:Windows","", @SW_SHOW, 8) Sleep(2000) $PID2 = Run(@ComSpec & " /c dir C:\Windows\System32\","", @SW_SHOW, 8) Sleep(2000) $Text = StdoutRead($PID1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Text = ' & $Text & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $text2 = StdoutRead($PID2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $text2 = ' & $text2 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
javip Posted September 12, 2012 Author Share Posted September 12, 2012 Run this script in SciTE and observe the console output. Then change the variable $PID2 to $PID1 in the Run line and the StdOutRead line, and see what you get in the console. $PID1 = Run(@ComSpec & " /c dir C:Windows","", @SW_SHOW, 8) Sleep(2000) $PID2 = Run(@ComSpec & " /c dir C:\Windows\System32\","", @SW_SHOW, 8) Sleep(2000) $Text = StdoutRead($PID1) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Text = ' & $Text & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $text2 = StdoutRead($PID2) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $text2 = ' & $text2 & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console I get a possibly used before declaration error. when i change $PID2 to $PID1. Also, something i tried. tried using your example in my function. i know it wasn't meant for this but here's what i tried. $IPN2 = StdoutRead($IPN) $IPN = RunWait(@ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) GUICtrlSetData($hEdit, $IPN2, 1) Sleep(2000) $NET2 = StdoutRead($NET) $NET = Run(@ComSpec & " /c netsh /?", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) GUICtrlSetData($hEdit, $NET2, 1) independent variables. but nothing displays. just something i was trying out. thanks for all the help so far. Link to comment Share on other sites More sharing options...
javip Posted September 12, 2012 Author Share Posted September 12, 2012 Also, if i use this: $data = StdoutRead($IPN) $datar = StdoutRead($NET) If $data Then GUICtrlSetData($hEdit, $data, 1) ElseIf $datar Then GUICtrlSetData($hedit, $datar,1) EndIf i get the same thing, last command outputs properly. am i doing the same thing by declaring two variables with the STDOUTREAD? i mean overriding the PID you spoke of. modifed code to reflect the above: $IPN = RunWait(@ComSpec & " /c notepad", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Sleep(2000) $NET = Run(@ComSpec & " /c netsh /?", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Link to comment Share on other sites More sharing options...
javip Posted September 17, 2012 Author Share Posted September 17, 2012 (edited) so after a few days of more searching i finally found the answer i need in a "Do" here's the code in case anyone is interested:$IPN = Run(@ComSpec & " /c ipconfig /renew ", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Do $dataIPN &= StdoutRead($IPN) Until @error GUICtrlSetData($hedit, $dataIPN) $IPN = Run(@ComSpec & " /c netsh /?", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Do $dataIPN &= StdoutRead($IPN) Until @error GUICtrlSetData($hedit, $dataIPN)this works with one variable getting populated by stdout multiple times or different named variables getting populated by stdout.using a While Wend Loop did not work at all whether using one variable multiple times or multiple variables all named differently.thanks for all the help everyone. learned alot about the way stdoudread works and doesn't work.even doing like the above where the varable get's redeclared did not work with a While Wend Loop. Edited September 17, 2012 by pixeldotz Link to comment Share on other sites More sharing options...
BrewManNH Posted September 17, 2012 Share Posted September 17, 2012 (edited) so after a few days of more searching i finally found the answer i need in a "Do" using a While Wend Loop did not work at all whether using one variable multiple times or multiple variables all named differently. Then I can only assume you did it wrong, because it works just fine in a While loop, as the example in the help file uses one. . even doing like the above where the varable get's redeclared did not work with a While Wend Loop. Here's your script as posted above modified to use a While loop instead of a Do loop, to demonstrate that both can be used to read StdOut and StdErr (if needed). $IPN = Run(@ComSpec & " /c ipconfig /renew ", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $dataIPN &= StdoutRead($IPN) If @error Then ExitLoop WEnd GUICtrlSetData($hedit, $dataIPN) $IPN = Run(@ComSpec & " /c netsh /?", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $dataIPN &= StdoutRead($IPN) If @error Then ExitLoop WEnd GUICtrlSetData($hedit, $dataIPN) Edited September 17, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
javip Posted September 17, 2012 Author Share Posted September 17, 2012 can you shed some light on the significance of the "&" next to $data? while it is in my example i'm not sure what it does. the information i found on the net had it posted with the "&" and so that's the reason i have it like that.also, here's a point to clarify, a backup of my files shows that i tried it exactly as you have posted. i tried that again and it failed. the example in the help file shows it like i have it in my code. the only difference between mine and what you posted is that mine does not include the "&" after $data. in the help file the ampersand is not included either. but yours obviously worked and mine didn'tagain thanks for the help and the alternative way of getting what i needed, but could the "&" have been causing the issue i was experiencing? Link to comment Share on other sites More sharing options...
BrewManNH Posted September 17, 2012 Share Posted September 17, 2012 $dataIPN &= StdoutRead($IPN) means, take the contents of $dataIPN and append to it the return from StdOutRead($IPN) so that now $dataIPN contains the data that it did before with the addition of whatever it got from the StdOutRead function. ; Example: $Data = "" ; start with an empty variable $Data For $I = 1 to 10 $Data &= $I ; Add the value of variable $I to the variable $Data Next MsgBox(64, "", "$Data = " & $Data) ; in this case the & is there to join 2 statements together If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
javip Posted September 19, 2012 Author Share Posted September 19, 2012 thank you. that explains alot. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now