Leaderboard
Popular Content
Showing content with the highest reputation on 05/01/2015 in all areas
-
_RunDos and StdErr
SadBunny and one other reacted to toasterking for a topic
I also have this function that I wrote that makes it easy for me to call a Windows console application and get its output using a single line of AutoIt code. I hope it's helpful to you. #include <Constants.au3> ; #FUNCTION# ==================================================================================================================== ; Name ..........: _RunWaitGet ; Description ...: Runs the specified process, waits for it to exit, then returns the contents of its StdOut and/or StdErr streams. ; Handy for running command-line tools and getting their output. ; Syntax ........: _RunWaitGet($sProgram, $sWorkingDir, $nShowFlag, $nOptions) ; Parameters ....: $sProgram - The full path of the program (EXE, BAT, COM, or PIF) to run ; $sWorkingDir - The working directory. Blank ("") uses the current working directory. ; This is not the path to the program. ; $nShowFlag - The "show" flag of the executed program: ; @SW_HIDE = Hidden window (or Default keyword) ; @SW_MINIMIZE = Minimized window ; @SW_MAXIMIZE = Maximized window ; $nOptions - 1 = Capture the StdOut stream only. ; $nOptions - 2 = Capture the StdErr stream only. ; $nOptions - 3 = Capture both the StdOut and StdErr streams. ; Return values .: String value containing the captured contents. ; If there was a problem running the process, @error is set to the @error value returned by Run(). ; Otherwise, @error is 0. ; Author ........: ToasterKing ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: MsgBox(0,"System Info",_RunWaitGet(@SystemDir & "\systeminfo.exe","",@SW_HIDE,1)) ; MsgBox(0,"Windows Version",_RunWaitGet(@ComSpec & " /c ver","",@SW_HIDE,1)) ; =============================================================================================================================== Func _RunWaitGet($sProgram,$sWorkingDir,$nShowFlag,$nOptions) Local $nRunOptFlags = 0,$sStreamOut = "" ; Initialize variables ; Determine flags for parent/child interaction If $nOptions = 1 Then $nRunOptFlags = $STDOUT_CHILD ElseIf $nOptions = 2 Then $nRunOptFlags = $STDERR_CHILD ElseIf $nOptions = 3 Then $nRunOptFlags = $STDOUT_CHILD + $STDERR_CHILD EndIf Local $hRunStream = Run($sProgram,$sWorkingDir,$nShowFlag,$nRunOptFlags) ; Run the process If @error Then Return SetError(@error,@extended,0) ; If there was an error code, return it. Otherwise... While 1 ; Loop until the end of the stream, which indicates that the process has closed it (which usually means the process ended) If BitAND($nOptions,1) Then ; If user specified to capture STDOUT stream... $sStreamOut &= StdoutRead($hRunStream) ; Append new stream contents to existing variable while removing those contents from the stream. If @error = 2 Then ExitLoop ; If stream ended, stop looping. EndIf If BitAND($nOptions,2) Then ; If user specified to capture STDERR stream... $sStreamOut &= StderrRead($hRunStream) ; Append new stream contents to existing variable while removing those contents from the stream. If @error = 2 Then ExitLoop ; If stream ended, stop looping. EndIf Sleep(100) ; To avoid overloading the CPU WEnd Return SetError(0,0,$sStreamOut) ; Return the captured contents and @error = 0 EndFunc2 points -
No sure what the attached code has to do with your question as that only shows some code for a GUI. So again: What do you exactly want to do? ps.. Please don't call me Dear as I am not your girl/boyfriend Jos1 point
-
Maybe you could help us to help you by showing what you already have and what you exactly want to accomplish? Jos1 point
-
zxtnt09, A search of the forum turned up many similar threads, this among them... kylomas1 point
-
Forum upgraded to v4.0.3 - General bug fixes. Release Notes1 point
-
? #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: Bacilic Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) Global $iMinNumber = 0 Global $iMaxNumber = 0 Global $iSelectNumber = 0 Global $iGivenNumber = 0 Global $iCount = 0 ; Main Form $hFormDynamicRange = GUICreate("Dynamic Ragne", 344, 147, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close") ; Inputs box: Min, Max and Given Number $hInputMin = GUICtrlCreateInput("1", 64, 32, 65, 21) $hInputMax = GUICtrlCreateInput("100", 64, 64, 65, 21) $hInputGiveNumber = GUICtrlCreateInput("", 152, 64, 65, 21) ; Buttons: Select and Check $hButtonSelect = GUICtrlCreateButton("Select", 240, 96, 67, 25) GUICtrlSetTip(-1, "Selects a number and resets the counter") GUICtrlSetOnEvent(-1, "On_Button") $hButtonCheck = GUICtrlCreateButton("Check", 152, 96, 67, 25) GUICtrlSetOnEvent(-1, "On_Button") ; Mesage labels: Dynamic Range, Counts and Select Number $hLabelDynamicRange = GUICtrlCreateLabel("Dynamic range", 192, 32, 75, 17) $hLabelSelectNumber = GUICtrlCreateLabel("Select Number", 240, 72, 74, 17, $SS_CENTER) $hLabelShowCount = GUICtrlCreateLabel("Efforts", 112, 96, 34, 17) ; Static Labels: Min, Max, Counter, Explanation and Range $hLabelMin = GUICtrlCreateLabel("Min:", 40, 32, 24, 17) $hLabelMax = GUICtrlCreateLabel("Max:", 32, 64, 27, 17) $hLabelRange = GUICtrlCreateLabel("Range:", 152, 32, 39, 17) $hLabelCounter = GUICtrlCreateLabel("Counter:", 64, 96, 44, 17) $hLabelExplanation = GUICtrlCreateLabel("Until the counter become zero, range must also change dynamically.", 8, 8, 337, 17) GUISetState() While 1 Sleep(10) WEnd Func On_Close() Switch @GUI_WinHandle Case $hFormDynamicRange Exit EndSwitch EndFunc ;==>On_Close Func On_Button() Switch @GUI_CtrlId Case $hButtonSelect $iMinNumber = Number(GUICtrlRead($hInputMin)) $iMaxNumber = Number(GUICtrlRead($hInputMax)) $iSelectNumber = _GuessNumber($iMinNumber, $iMaxNumber) GUICtrlSetData($hLabelSelectNumber, $iSelectNumber) GUICtrlSetData($hLabelDynamicRange, $iMinNumber & " - " & $iMaxNumber) $iCount = 0 ; Reset counter GUICtrlSetData($hLabelShowCount, $iCount) Case $hButtonCheck $iCount = $iCount + 1 $iGivenNumber = Number(GUICtrlRead($hInputGiveNumber)) $aDynamicRange = _Range($iGivenNumber, $iSelectNumber, $iMinNumber, $iMaxNumber) GUICtrlSetData($hLabelDynamicRange, $aDynamicRange[0] & " - " & $aDynamicRange[1]) GUICtrlSetData($hLabelShowCount, $iCount) GUICtrlSetData($hInputMin, $aDynamicRange[0]) GUICtrlSetData($hInputMax, $aDynamicRange[1]) EndSwitch EndFunc ;==>On_Button Func _GuessNumber($iMin, $iMax) ; Returns a random integer between minimum and maximum $iRandomNumber = Random($iMin, $iMax, 1) Return $iRandomNumber EndFunc ;==>GuessNumber Func _Range($iInput, $iSelect, $iMin, $iMax) ; Returns the range of the numbers in which the random number included Local $aRange[2] If $iInput < $iSelect Then $aRange[0] = $iInput $aRange[1] = $iMax $iMinNumber = $iInput Else $aRange[0] = $iMin $aRange[1] = $iInput $iMaxNumber = $iInput EndIf Return $aRange EndFunc ;==>_Range1 point
-
_RunDos and StdErr
SuperFletch reacted to SadBunny for a topic
Almost, but not exactly. First, you have a rogue equals-sign (StdoutRead=($pid)) that needs to go. Then, you will want to either wait for the process to close or have the reading done in a loop, since not all the output may come in in the first buffer. The helpfile contains a working example: https://www.autoitscript.com/autoit3/docs/functions/StdoutRead.htm Note: if you just want the stdout from a dos command redirected to the stderr stream, dos supports stream redirection: command >&2 Or for the reverse, redirect stderr to stdout: command 2>&1 Or to redirect both the stdout and stderr to a file: command > file 2>&1 (Just in case you didn't know.)1 point -
_RunDos and StdErr
SuperFletch reacted to Bert for a topic
RunDOS runs the command in a hidden DOS window. Have you looked at StdoutRead?1 point -
Your original code added some commas to the string. Try adding MsgBox(0,0,$final_path) after you construct it with all the string concatenation... That's probably it. /edit: oh, wait, now I see what you tried to do. Functions don't work that way. A function that takes three arguments is not "secretly a function that takes only one argument but with commas in it"... You have to actually separate the arguments. Which is of course what Water's code did. Consider this "in-between form", maybe it explains it better. (The naming is intentionally bad, to show the three arguments. Water's naming is what you should use. $sArg1_part1 = "C:\CHDKPTP\" $sArg1_part2 = "chdkptp.exe" $sArg1_part3 = "-i" $sArg2 = "" $iArg3 = @SW_MAXIMIZE $final_arg1 = $sArg1_part1 & $sArg1_part2 & " " & $sArg1_part3 Global $iProcessID = Run($final_arg1, $sArg2, $iArg3)If this is hard to understand, maybe it's a good idea to practice writing a script that contains a function of your own with parameters. Say, try to make this broken piece of code work: $answer = addTwoNumbers(2, 5) msgbox(0,0,$answer) $answer = addTwoNumbers(10, 20) msgbox(0,0,$answer) func addTwoNumbers() return ??? ; make this return the correct value EndFunc1 point
-
I didn't spend too much time checking your code but I think the way you passed the data to Run everything was seen as a single parameter not as 3 as needed.1 point