JeffQOOQAAA Posted August 15, 2017 Share Posted August 15, 2017 Dear All. I want to use Autoit get cmd output. Here is my code, but no ouput, Please help to correct where is error, thanks! #include <Constants.au3> Local $hWnd = Winactivate("Administrator: Command Prompt") ; Display a list of Notepad processes returned by ProcessList. Local $aProcessList = ProcessList("cmd.exe") For $i = 1 To $aProcessList[0][0] MsgBox(0, "", $aProcessList[$i][0] & @CRLF & "PID: " & $aProcessList[$i][1]) ;$iPID = $aProcessList[$i][1] Local $content = StdoutRead($aProcessList[$i][1]) MsgBox(0, "讀取到的 STDOUT 為:", $content) FileWrite(@DesktopDir &"\Test.txt", $content &@CRLF) Next Link to comment Share on other sites More sharing options...
SlackerAl Posted August 15, 2017 Share Posted August 15, 2017 (edited) I just ran this and it did what I would expect it to: I had two cmd.exe processes running (according to task manager), your code went through the For loop twice, the first MsgBox reported the process name and PID, the second was empty: You are using StdoutRead, which gives you the STDOUT stream from a previously run process, but the ProcessList function call is not a child process and you do not create any other child processes, hence STDOUT is empty. Perhaps if you explain in more detail what you want your code to do we can suggest an alternative approach? Edited August 15, 2017 by SlackerAl Problem solving step 1: Write a simple, self-contained, running, replicator of your problem. Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted August 16, 2017 Author Share Posted August 16, 2017 I have an system, and execute some program will popup cmd on system So, I need to develop autoit tool to found cmd window and output for me. But I don't know how to implement....... Link to comment Share on other sites More sharing options...
KickStarter15 Posted August 16, 2017 Share Posted August 16, 2017 Hi, Try checking this link if that suffice your expectation. And check with help file about Run and StdoutRead as what SlackerAl means. KS15 Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
JeffQOOQAAA Posted August 16, 2017 Author Share Posted August 16, 2017 Hi My problem is cmd create not through autoit. I just used autoit to found already exist cmd and get output..... Link to comment Share on other sites More sharing options...
KickStarter15 Posted August 16, 2017 Share Posted August 16, 2017 Let me see if I have it clearly. You want to get the output from a cmd.exe with Autoit? is that right? Like: Run(@ComSpec & " /c dir > output.txt", @ScriptDir) Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. 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