Nisteo Posted February 24, 2023 Share Posted February 24, 2023 My idea is to run functions interactively from a console window. But "Execute" can never execute, lol. #AutoIt3Wrapper_Change2CUI=y Global $sStdIn, $sExecReturn While 1 $sStdIn = ConsoleRead() If $sStdIn <> "" Then $sExecReturn = Execute($sStdIn) If @error Then MsgBox(16, "Error", "Cannot execute: " & $sStdIn) Else ConsoleWrite($sExecReturn) EndIf EndIf Sleep(10) WEnd If I add quotes like this: Execute('"' & $sStdIn & '"') then "Execute" just returns $sStdIn without executing. Also, if I compile it in GUI mode and pipe STDIN of this script to STDOUT of another non-console application, then everything works as expected. What I'm doing wrong? Link to comment Share on other sites More sharing options...
Solution mistersquirrle Posted February 24, 2023 Solution Share Posted February 24, 2023 (edited) I think similar to Part of the problem is how the 'Console' works in an uncompiled script. You're running it through the AutoIt.exe process, not through SciTE or its own process. You're not inputting into the 'correct' console window, is basically my thought. So, basically, you cannot do what you want unless you compile the script, and do you things from the console window of the direct .exe file. As for why Execute is not working, that's because of CR/LF/CRLF, basically. I tested your code, and some example code built from the help file entry for Execute, and I got it working: expandcollapse popup#include <MsgBoxConstants.au3> #cs Compile this script to "ConsoleRead.exe". Open a command prompt to the directory where ConsoleRead.exe resides. Type the following on the command line: echo Hello! | ConsoleRead.exe When invoked in a console window, the above command echos the text "Hello!" but instead of displaying it, the | tells the console to pipe it to the STDIN stream of the ConsoleRead.exe process. #ce ; MouseClick("main", 436, 451, 1, 10) ; Copy this and try executing that, or whatever you want Example() Func Example() If Not @Compiled Then MsgBox($MB_SYSTEMMODAL, "", "This script must be compiled in order to run the example.") Exit EndIf Local $sOutput While True Sleep(25) $sOutput = ConsoleRead() ;~ If @error Then ExitLoop If $sOutput <> '' Then MsgBox($MB_SYSTEMMODAL, "", "Received: " & @CRLF & 'Type: ' & VarGetType($sOutput) & @CRLF & $sOutput) Execute(StringStripCR(StringStripWS($sOutput, 1 + 2))) ; $STR_STRIPLEADING + $STR_STRIPTRAILING If @error Then MsgBox($MB_SYSTEMMODAL, "", "Execute $sOutput error: " & @CRLF & @CRLF & @error) EndIf EndIf WEnd MsgBox($MB_SYSTEMMODAL, "", "Received: " & @CRLF & @CRLF & $sOutput) EndFunc ;==>Example Give that a shot (compiled) and see if it works for you, it did for me (sending the MouseClick line in there). Keep in mind then that this will only work for single line things. Edit: Also take a look at https://www.autoitscript.com/autoit3/docs/intro/running.htm, specifically: AutoIt specific command Line Switches Quote Run a single line of code: AutoIt3.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line" Execute one line of code. The command below will execute that single line of code and display the MsgBox with "Hello World!". The tray icon will not be displayed. @@SyntaxHighlighting@@ Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4096, ''Hello World!'', ''Hi!'')"') @@End@@ Run a script using another compiled script: Compiled.exe [/ErrorStdOut] /AutoIt3ExecuteScript file [params ...] Execute another AutoIt script file from a compiled AutoIt3 executable. Compiled.exe [/ErrorStdOut] /AutoIt3ExecuteLine "command line" Execute one line of code as with AutoIt3.exe above. And keep in mind that to use AutoIt3ExecuteScript or AutoIt3ExecuteLine, the file needs to be compiled with this flag: #pragma compile(AutoItExecuteAllowed, true) Edited February 24, 2023 by mistersquirrle ioa747 and Nisteo 1 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
Nisteo Posted February 24, 2023 Author Share Posted February 24, 2023 @mistersquirrle Thank you. My problem was in trailing whitespace 😁 Execute(StringStripWS($sStdIn, 2)) 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