Jump to content

Recommended Posts

Posted

Hello,

I have process id of CMD and i want to read output from it. i have used StdoutRead but it does not work.

for example: i start CMD without using Autoit, then i get the process ID, then i use Autoit to read the output using pID, but it does not work.

Pls help

thanks

Posted

I lost my crystal ball so if you would post your code and the error or what exactly is not working will help a lot until i find it

Posted (edited)
  On 1/25/2017 at 11:34 AM, Juvigy said:

I lost my crystal ball so if you would post your code and the error or what exactly is not working will help a lot until i find it

Expand  

#include <Constants.au3>

Local $iPID = InputBox("Input process id of CMD", "Input process id of CMD")
Local $sStdOut = ""
While 1
    $sStdOut &= StdoutRead($iPID)
    ConsoleWrite(StdoutRead($iPID) & @CRLF)
    If @error Then ExitLoop
Wend

Here is the code

Edited by luckyluke
Posted
  On 1/26/2017 at 2:51 AM, ripdad said:

try this...

Local $iPID = Run('cmd /?', '', @SW_HIDE, 2); $STDOUT_CHILD
If @error Or Not $iPID Then Exit
Local $sStdOut = ""

Do
    Sleep(10)
    $sStdOut &= StdoutRead($iPID)
Until @error

MsgBox(0, '', $sStdOut)

Thank you, but the point is i want the script to read from CMD, i dont want it run CMD command and read.

If the script run CMD, it will read the data out, but is there any way i can read it by using process ID?

Expand  

 

Posted
  On 1/26/2017 at 2:14 PM, Juvigy said:
StdoutRead($iPID)

Doesn't work like that - it needs the PID returned from a child process and a RUN command. What exactly do you want to accomplish in more details?

Expand  

Hi, here is the steps:

1. i start cmd in windows. open task manager to get the process ID of CMD

2. I run autoit script, then put the ID i got from step 1, then the script will need to read output from cmd. for example in cmd i type "help", then the script will read the output from cmd.

Is that ok?

Posted
  On 1/30/2017 at 2:25 AM, luckyluke said:

Hi, here is the steps:

1. i start cmd in windows. open task manager to get the process ID of CMD

2. I run autoit script, then put the ID i got from step 1, then the script will need to read output from cmd. for example in cmd i type "help", then the script will read the output from cmd.

Is that ok?

Expand  

Why not just run "wmic process list as part of the script.  The command will list detailed information about each process, including PID.  That may allow you to associate the process name to the pid:

$proc = Run ( @ComSpec & " /c wmic process list", @SystemDir, Default, $STDOUT_CHILD )
ProcessWaitClose ( $proc )
$list = StdoutRead ( $proc )
MsgBox ( 1, "Processes", $list )

 

Posted

I told you - it doesnt work like this. You have to start the CMD from the script with run and then it will work. You cant attach to manually started CMD.

I found and old topic where this was implemented , but i cant make it work with the new AutoIt. It is here:

 

Posted
  On 1/30/2017 at 3:44 AM, MattHiggs said:

Why not just run "wmic process list as part of the script.  The command will list detailed information about each process, including PID.  That may allow you to associate the process name to the pid:

$proc = Run ( @ComSpec & " /c wmic process list", @SystemDir, Default, $STDOUT_CHILD )
ProcessWaitClose ( $proc )
$list = StdoutRead ( $proc )
MsgBox ( 1, "Processes", $list )

 

Expand  

The point is i want to get text from CMD which is run by other program. so we cant start CMD using autoit.

Posted
  On 1/30/2017 at 12:43 PM, Juvigy said:

I told you - it doesnt work like this. You have to start the CMD from the script with run and then it will work. You cant attach to manually started CMD.

I found and old topic where this was implemented , but i cant make it work with the new AutoIt. It is here:

Thank you, Juvigy. That is really help. I checked it and tested, it worked for me. 

The script using clipget function to get information from CMD command. But one small thing is that if a user using copy paste command (by press Ctrl+C) then it will be messed up.

Expand  

 

Posted (edited)

Please stop the quoting, just reply, quotes are meant for parts you want to refer to.

Even weirder is including your answer inside the quote.

Anyway, here's my thought on the way to solve it.

Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
$hCmd = InputBox("Input", "Input title of CMD window"&@crlf&"(doesn't have to be complete)")
If @error Or $hCmd = '' Then Exit
WinActivate($hCmd)
SendKeepActive($hCmd)
$cmdtext2 = ClipGet()
Send( "! es{Enter}" )
$cmdtext = ClipGet()
ClipPut($cmdtext2)
MsgBox(64, '', $cmdtext)

This keeps your copy/paste text, because it copies to variable does it's thing and copies stuff back again, so it won't mess up copy paste.

Edited by careca
  Reveal hidden contents

IUIAutomation - Topic with framework and examples

Au3Record.exe

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...