Zad

Need help saving dos command output to a variable

3 posts in this topic

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

Share this post


Link to post
Share on other sites



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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Jos,

Thanks it worked out great!

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