Jump to content

Need help saving dos command output to a variable

Recommended Posts

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)


            $Message = FileRead ("temp.txt", fileGetSize("temp.txt"))


            if fileGetSize("temp.txt") = "0" Then
               GUICtrlSetData($Label_4, "Account does NOT Exist")

            GUICtrlSetData($Label_4, $Message)

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.

; 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



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

  • Create New...