Zad Posted October 15, 2015 Share Posted October 15, 2015 I tried for several hours to try to save output from a command run by the Run command, but was not successful. I ended up having to save the output to a file and then read the contents of the file into a variable which makes it very inefficient and slow. Can someone help me with changing the code below so that it saves the output of the "net user" command being run by the Autoit "Run" function into a variable named #Message without having to write to a file and then read the file contents and save to a variable? I appreciate any help provided. Here is the code below: $DOS = Run(@ComSpec & " /c net user " & $input & " /domain | find /I ""account active""" & ">" & "temp.txt", "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD) Sleep(1000) $Message = FileRead ("temp.txt", fileGetSize("temp.txt")) if fileGetSize("temp.txt") = "0" Then GUICtrlSetData($Label_4, "Account does NOT Exist") Else GUICtrlSetData($Label_4, $Message) EndIf Link to comment Share on other sites More sharing options...
Developers Jos Posted October 15, 2015 Developers Share Posted October 15, 2015 This works fine for me on my Laptop:#include <AutoItConstants.au3> $input = "Jos" $DOS = Run(@ComSpec & ' /c net user ' & $input & ' | find /I "Account active"', "", @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD) ; Wait until the process has closed using the PID returned by Run. ProcessWaitClose($DOS) ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead. $Message = StdoutRead($DOS) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Message = ' & $Message & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Zad Posted October 15, 2015 Author Share Posted October 15, 2015 Jos,Thanks it worked out great! 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