Emolas Posted February 15, 2023 Share Posted February 15, 2023 I have a batch file calling a compiled autoit file and I want the autoit to write to the DOS window that the batch file opened. For instance: test.bat contains the following start /wait script.exe script.exe contains the following: ConsoleWrite("this is a test") Exit I know consolewrite isn't the way to do it but I can't seem to find a way to write to the window that ran the script. Lots of ways to write to windows that the script opens but nothing the other way around. Link to comment Share on other sites More sharing options...
Nisteo Posted February 15, 2023 Share Posted February 15, 2023 When you compile an AutoIt script in CUI mode, the output of all console applications launched from this script occurs in the same window. So you need to run things from AutoIt, not from batch. #AutoIt3Wrapper_Change2CUI=y Run("start /wait test.exe") Link to comment Share on other sites More sharing options...
mistersquirrle Posted February 15, 2023 Share Posted February 15, 2023 As Nisteo said, if your AutoIt script launches the exe, it can read the output from the launched script: #AutoIt3Wrapper_Change2CUI=y #include <AutoItConstants.au3> Local $iPid = Run("test.exe", @ScriptDir, @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($iPid) ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead. Local $sOutput = StdoutRead($iPid) ConsoleWrite($sOutput & @CRLF) However I'm not aware of a way for the child/launched process to read output from the main/launcher script. If you want to communicate between processes, check out the IPC methods: https://www.autoitscript.com/wiki/User_Defined_Functions#Inter_Process_Communications Is there something specific that you're looking to do? Maybe there's a solution besides reading output from either process. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Trong Posted February 16, 2023 Share Posted February 16, 2023 You need to call it directly instead of using start! For example: test.bat contains the following script.exe script.exe compiled with the code: #AutoIt3Wrapper_Change2CUI=y #pragma compile(Console, true) Opt('TrayMenuMode',1) ConsoleWrite("this is a test") Sleep(2000) ; Stop the screen to let you see ! ConsoleWrite("this is a test 2") Sleep(5000) ; Stop the screen to let you see ! Exit Regards, Link to comment Share on other sites More sharing options...
LarsJ Posted February 16, 2023 Share Posted February 16, 2023 You do it this way. tst00.cmd: start "CmdIdentifierString" /wait tst00.exe tst00.au3: #AutoIt3Wrapper_Change2CUI=Y ;#RequireAdmin ; Maybe you need #RequireAdmin rights? ; Maybe exclude exe/folder from antivirus program? DllCall( "Kernel32.dll", "int", "AttachConsole", "dword", WinGetProcess( "CmdIdentifierString" ) ) Func CmdConsoleWrite( $sStr ) DllCall( "Kernel32.dll", "bool", "WriteConsoleW", "handle", _ DllCall( "Kernel32.dll", "handle", "GetStdHandle", "int", -11 )[0], _ ; -11 = STD_OUTPUT_HANDLE "wstr", $sStr, "dword", StringLen( $sStr ), "dword*", 0, "ptr", 0 ) EndFunc CmdConsoleWrite( @CRLF ) For $i = 1 To 5 CmdConsoleWrite( "This is test number " & $i & @CRLF ) If $i < 5 Then Sleep( 3000 ) Next Exit Run tst00.cmd in a Command Prompt or double-click. Tested on Windows 7 as 32/64 bit code. mLipok 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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