luckyluke Posted January 25, 2017 Share Posted January 25, 2017 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 Link to comment Share on other sites More sharing options...
Juvigy Posted January 25, 2017 Share Posted January 25, 2017 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 Link to comment Share on other sites More sharing options...
luckyluke Posted January 26, 2017 Author Share Posted January 26, 2017 (edited) 14 hours ago, 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 #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 January 26, 2017 by luckyluke Link to comment Share on other sites More sharing options...
ripdad Posted January 26, 2017 Share Posted January 26, 2017 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) Ascer 1 "The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward Link to comment Share on other sites More sharing options...
luckyluke Posted January 26, 2017 Author Share Posted January 26, 2017 8 hours ago, 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? Link to comment Share on other sites More sharing options...
Juvigy Posted January 26, 2017 Share Posted January 26, 2017 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? Link to comment Share on other sites More sharing options...
luckyluke Posted January 30, 2017 Author Share Posted January 30, 2017 On 1/26/2017 at 9: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? 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? Link to comment Share on other sites More sharing options...
MattHiggs Posted January 30, 2017 Share Posted January 30, 2017 1 hour ago, 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? 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 ) Link to comment Share on other sites More sharing options...
Juvigy Posted January 30, 2017 Share Posted January 30, 2017 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: luckyluke 1 Link to comment Share on other sites More sharing options...
luckyluke Posted January 31, 2017 Author Share Posted January 31, 2017 23 hours ago, 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 ) The point is i want to get text from CMD which is run by other program. so we cant start CMD using autoit. Link to comment Share on other sites More sharing options...
luckyluke Posted January 31, 2017 Author Share Posted January 31, 2017 14 hours ago, 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. Link to comment Share on other sites More sharing options...
Juvigy Posted February 1, 2017 Share Posted February 1, 2017 Can you post your code? I was not able to make it work. What is your Autoit version ? Link to comment Share on other sites More sharing options...
careca Posted February 1, 2017 Share Posted February 1, 2017 (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 February 1, 2017 by careca Blue0 1 Spoiler Renamer - Rename files and folders, remove portions of text from the filename etc. GPO Tool - Export/Import Group policy settings. MirrorDir - Synchronize/Backup/Mirror Folders BeatsPlayer - Music player. Params Tool - Right click an exe to see it's parameters or execute them. String Trigger - Triggers pasting text or applications or internet links on specific strings. Inconspicuous - Hide files in plain sight, not fully encrypted. Regedit Control - Registry browsing history, quickly jump into any saved key. Time4Shutdown - Write the time for shutdown in minutes. Power Profiles Tool - Set a profile as active, delete, duplicate, export and import. Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes. NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s. IUIAutomation - Topic with framework and examples Au3Record.exe Link to comment Share on other sites More sharing options...
luckyluke Posted February 6, 2017 Author Share Posted February 6, 2017 Juvigy check the careca 's code, it worked for me. Link to comment Share on other sites More sharing options...
Juvigy Posted February 7, 2017 Share Posted February 7, 2017 Gr8. Thanks careca It works for me too. 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