Jump to content

StdoutRead() can't find text in cmd console?

Recommended Posts

13 hours ago, LukeLe said:

@Blue0 Please check if this is what you're trying to achieve:

Run this:

#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

$iPID = Run(@ComSpec & " /C " & @DesktopDir & "\Test.bat", @DesktopDir, @SW_HIDE, $STDERR_MERGED)
$sTmp = ""
While ProcessExists($iPID)
    $sTmp = StdoutRead($iPID)
    If StringLen($sTmp) > 0 Then ConsoleWrite($sTmp)

Test.bat's content:

@echo off
echo restart bat to test restart word search
echo would you like to restart
echo press y to restart
echo press n to not restart

This is the output running on my computer:

+>13:19:48 Starting AutoIt3Wrapper v.19.102.1901.0 SciTE v.   Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:  utf8.auto.check:
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
restart bat to test restart word search
would you like to restart
press y to restart
press n to not restart
Press any key to continue . . . 
+>13:19:48 AutoIt3.exe ended.rc:0
+>13:19:48 AutoIt3Wrapper Finished.
Process exited with code 0


Yes. And if I add the StringInStr it still works. ☺️ Unfortunately just noticed that there's a big problem with my test bat.. It only opens one cmd while the real one opens and closes few cmd windows.  


11 hours ago, Musashi said:

@Blue0 :

In your place I would really try to follow the advice of @jchd (if possible). Most installers can be controlled via command line parameters, such as /SILENT , /NORESTART and so on. This is more reliable than processing CMD console streams.

Here e.g. a list of command line arguments for MSIEXEC :


  Reveal hidden contents

Windows Installer (MSIEXEC)

Documented command line arguments

Type MSIEXEC /? and you'll get the following on-screen help:

	Windows ® Installer. V 5.0.7601.17514
	msiexec /Option <Required Parameter> [Optional Parameter]
	Install Options
		</package | /i> <Product.msi>
			Installs or configures a product
		/a <Product.msi>
			Administrative install - Installs a product on the network
		/j<u|m> <Product.msi> [/t <Transform List>] [/g <Language ID>]
			Advertises a product - m to all users, u to current user
		</uninstall | /x> <Product.msi | ProductCode>
			Uninstalls the product
	Display Options
			Quiet mode, no user interaction
			Unattended mode - progress bar only
			Sets user interface level
			n - No UI
			b - Basic UI
			r - Reduced UI
			f - Full UI (default)
			Help information
	Restart Options
			Do not restart after the installation is complete
			Prompts the user for restart if necessary
			Always restart the computer after installation
	Logging Options
		/l[i|w|e|a|r|u|c|m|o|p|v|x|+|!|*] <LogFile>
			i - Status messages
			w - Nonfatal warnings
			e - All error messages
			a - Start up of actions
			r - Action-specific records
			u - User requests
			c - Initial UI parameters
			m - Out-of-memory or fatal exit information
			o - Out-of-disk-space messages
			p - Terminal properties
			v - Verbose output
			x - Extra debugging information
			+ - Append to existing log file
			! - Flush each line to the log
			* - Log all information, except for v and x options
		/log <LogFile>
			Equivalent of /l* <LogFile>
	Update Options
		/update <Update1.msp>[;Update2.msp]
			Applies update(s)
		/uninstall <PatchCodeGuid>[;Update2.msp] /package <Product.msi | ProductCode>
			Remove update(s) for a product
	Repair Options
		/f[p|e|c|m|s|o|d|a|u|v] <Product.msi | ProductCode>
			Repairs a product
			p - only if file is missing
			o - if file is missing or an older version is installed (default)
			e - if file is missing or an equal or older version is installed
			d - if file is missing or a different version is installed
			c - if file is missing or checksum does not match the calculated value
			a - forces all files to be reinstalled
			u - all required user-specific registry entries (default)
			m - all required computer-specific registry entries (default)
			s - all existing shortcuts (default)
			v - runs from source and recaches local package
	Setting Public Properties
	Consult the Windows ® Installer SDK for additional documentation on the
	command line syntax.
	Copyright © Microsoft Corporation. All rights reserved.
	Portions of this software are based in part on the work of the Independent JPEG Group.

Undocumented (1) command line arguments

My colleague Adriaan Westra taught me the trick to suppress reboots when installing .MSI files from the command line (better believe me, /norestart rarely does what its name suggests):

MSIEXEC /i myfile.msi /qn REBOOT=ReallySuppress

This made me curious if there are more unknown arguments, so I started experimenting.
Try for yourself, type:


and you'll find the following "undocumented" command line arguments (called "Public Properties" in MSIEXEC's on-screen help) and their default values:

Note: (1) Actually these command line arguments are documented, but they are not mentioned in the on-screen help displayed when typing MSIEXEC /?.


It's just that I can't do that. I have to use the bat thanks to the policy of our company's project 😞. I guess I could make my own Autoit version if I knew how. There's some /x {123-123-123} stuff etc in the real bat. Almost 40 lines of stuff.


9 hours ago, rudi said:


this should help you out of your Problem:


#include <AutoItConstants.au3>


FileWriteLine($hBat,'@echo off')
FileWriteLine($hBat,'echo this is the first echo line')
FileWriteLine($hBat,'echo this is the second line')
FileWriteLine($hBat,'choice /c YN /m "do you want to restart?"')
FileWriteLine($hBat,'if errorlevel 2 goto EXIT')
FileWriteLine($hBat,'if errorlevel 1 goto RESTART')
FileWriteLine($hBat,'echo this is the END...')

$pid=Run(@ComSpec & ' /C "' &  $Bat & '"',@TempDir, @SW_HIDE, $STDIN_CHILD + $STDERR_MERGED)

while ProcessExists($pid)
    $StrOutput &= StdoutRead($pid)
    if StringInStr($StrOutput,$StrMatch) Then
        if $Found > 2 Then
    Sleep(100) ; waiting for BAT file to vanish

MsgBox(0,"Process vanished","number of matches found: " & $Found & @CRLF & $StrOutput)


  1. You have to add $STDIN_CHILD for your run command
  2. You have to use StdinWrite(), not "send()" to write to the console of your BAT file.


cu, Rudi.

PS: I guess that BAT file is maintained by some other Person or department, and so it's a "take it or leave it Option" to you.
Nevertheless it's worth a try, that +YOU+ encourage this other Person or dept to natively use autoit for These Tasks, as several other answers here mentioned before.

This works with the test bat. Thanks 😊. The real bat opens and closes a few cmd windows so it won't work. Trying to figure out how do I make this work on that 🤔

PS. Yes. It's "take it or leave" pretty much.


EDIT: Found this and I think this is what I need. Need to put WinWaitClose with timeout, search for the filter word, press key if it does find the filter in a loop. Should work.

On 2/1/2017 at 5:34 PM, careca said:

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
$cmdtext2 = ClipGet()
Send( "! es{Enter}" )
$cmdtext = ClipGet()
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 Blue0

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...