Sign in to follow this  
Followers 0
JeffQOOQAAA

get cmd output

6 posts in this topic

#1 ·  Posted

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by SlackerAl

Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.

Share this post


Link to post
Share on other sites

#3 ·  Posted

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.......

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

Hi,

Try checking this link if that suffice your expectation. And check with help file about Run and StdoutRead as what SlackerAl means.

 

 

KS15

Share this post


Link to post
Share on other sites

#5 ·  Posted

Hi 

My problem is cmd create not through autoit.

I just used autoit to found already exist cmd and get output.....

Share this post


Link to post
Share on other sites

#6 ·  Posted

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)

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  
Followers 0