66Gramms Posted June 21, 2021 Share Posted June 21, 2021 Hello! I have an au3 script from which I want to execute and wait for other au3 scripts, but I just can't get any data from Stdout which would be crucial. This is how I make the new process: Func RunAU3($scriptName, $absolutePath = @ScriptDir & "\Tests") Local $exitCode = 0 Local $pid = Run(@AutoItExe & ' "' & $absolutePath & "\" & $scriptName & '"', "", $STDOUT_CHILD) While ProcessExists($pid) local $sOutput = StdoutRead($pid) if @extended <> 0 Then MsgBox(0, "", $sOutput) Local $outputSplit = StringSplit($sOutput, ";") if ($outputSplit[1] = 2) Then $exitCode = 1 EndIf WriteLog($outputSplit[0], $outputSplit[1]) EndIf Wend return $exitCode EndFunc The script that I run from my code: ConsoleWrite("Lefut a viewertest;0") ;Sleep(5000) Exit 1 I've tried this sleep 5s because I thought maybe it writes to stdout but exits immediately after and my main process won't have the time to read the value (Though I am not entirely sure how Stdout works and if this could happen) but it didn't help so I've just commented it out. Any help would be much appreciated! Link to comment Share on other sites More sharing options...
66Gramms Posted June 21, 2021 Author Share Posted June 21, 2021 I've put an MsgBox on line 7 of the first script to see the data that comes through if any, but the msgbox won't even pop up, meaning that there is no data being read from Stdout (as it sets the @extended macro to the number of bytes read, according to documentation) Link to comment Share on other sites More sharing options...
oli_the_true_one Posted June 21, 2021 Share Posted June 21, 2021 Maybe try to add #AutoIt3Wrapper_Change2CUI=y at the top of your script ? #AutoIt3Wrapper_Change2CUI=y ConsoleWrite("Lefut a viewertest;0") ;Sleep(5000) Exit 1 From ConsoleWrite help file: Quote Scripts compiled as Console applications also have a STDOUT stream. Link to comment Share on other sites More sharing options...
Developers Jos Posted June 21, 2021 Developers Share Posted June 21, 2021 Are you sure the script is ran? Just add a msgbox to the second script to ensure it is! Is the first script ran with AutoIt3.exe or compiled? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
JockoDundee Posted June 21, 2021 Share Posted June 21, 2021 (edited) There is nothing but a function declaration… Try adding: RunAu3("YourScriptName") to the top of your script… Edited June 21, 2021 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
66Gramms Posted June 21, 2021 Author Share Posted June 21, 2021 1 hour ago, Jos said: Are you sure the script is ran? Just add a msgbox to the second script to ensure it is! Is the first script ran with AutoIt3.exe or compiled? Jos Yes I am sure the script is ran, I have added an msgbox previously, but removed by the time I shared the code. It is not compiled, just ran as a script. 2 hours ago, oli_the_true_one said: Maybe try to add #AutoIt3Wrapper_Change2CUI=y at the top of your script ? #AutoIt3Wrapper_Change2CUI=y ConsoleWrite("Lefut a viewertest;0") ;Sleep(5000) Exit 1 From ConsoleWrite help file: The code is on my work computer so I'll only be able to check this tomorrow. What is this line doing exactly? I've tried googling it but couldn't find any answers. Link to comment Share on other sites More sharing options...
Solution oli_the_true_one Posted June 21, 2021 Solution Share Posted June 21, 2021 Forget what I said about "#AutoIt3Wrapper_Change2CUI=y", it is irrelevant in your case. It's a compiler directive to display the ConsoleWrite output in windows command prompt which you are not doing. There is a missing parameter in the Run command. This is working for me: #include "AutoItConstants.au3" RunAU3("externalScript.au3") Func RunAU3($scriptName, $absolutePath = @ScriptDir & "\Tests") Local $exitCode = 0 Local $pid = Run(@AutoItExe & ' "' & $absolutePath & "\" & $scriptName & '"',"",@SW_HIDE, $STDOUT_CHILD) Sleep(1000) ConsoleWrite("$pid: " & $pid & @CRLF) Local $sOutput While ProcessExists($pid) $sOutput = StdoutRead($pid) if @extended <> 0 Then ConsoleWrite("$sOutput: " & $sOutput) EndIf WEnd return $exitCode EndFunc externalScript.au3: ;MsgBox(0,"external script","external script") For $i=0 To 10 ConsoleWrite("Lefut a viewertest;0" & @CRLF) Sleep(500) Next Exit 1 Console output of the main script: +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. $pid: 1808 $sOutput: Lefut a viewertest;0 Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 $sOutput: Lefut a viewertest;0 +>22:07:55 AutoIt3.exe ended.rc:0 +>22:07:55 AutoIt3Wrapper Finished. >Exit code: 0 Time: 7.156 66Gramms and JockoDundee 2 Link to comment Share on other sites More sharing options...
JockoDundee Posted June 21, 2021 Share Posted June 21, 2021 2 hours ago, oli_the_true_one said: There is a missing parameter in the Run command. Circle gets the square… Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
66Gramms Posted June 22, 2021 Author Share Posted June 22, 2021 I feel so dumb, that I've used the overload incorrectly. Thank you so much! 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