Jump to content
Sign in to follow this  
botanic

Dos output to variable

Recommended Posts

botanic

I need to get the output of a command that runs in a command prompt, the problem is that run only returns a 1 or 0. I tried

#RequireAdmin $Command="cmd /c dir c: /s";<-Your command 
RunWait($command & ">" & @scriptdir & "\output.txt","") 
$OutPut = FileRead( @scriptdir & "\output.txt",FileGetSize(@scriptdir & "\output.txt")) 
MsgBox(0, "", $OutPut)  
FileDelete( @scriptdir & "\output.txt")

however the output.txt is blank even tho there is output.

Edited by botanic

Share this post


Link to post
Share on other sites
TurionAltec

Using StdoutRead is a lot easier than using a temp file.

#include <Constants.au3>
#RequireAdmin 
$Command=@comspec & " /c dir c:\ /s";<-Your command 
$pid=Run($command,@SystemDir,@SW_HIDE,$STDERR_MERGED)
ProcessWaitClose($pid)
$output=StdoutRead($pid)
MsgBox(1,"output",$output)

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.