nill Posted June 23, 2023 Share Posted June 23, 2023 In the exe I wrote #pragma compile(Console, true) If I run it separately it works and logs are written But I execute it from other script autoit, and console window opens, but no logs. $iPID = Run(file_name.exe, @WorkingDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) This is needed to read everything that is printed to the console into a separate variable $sOut &= StdoutRead($iPID, False) Link to comment Share on other sites More sharing options...
Developers Jos Posted June 23, 2023 Developers Share Posted June 23, 2023 show the full code so we can see what you are doing and whether you are waiting long enough. 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...
nill Posted June 23, 2023 Author Share Posted June 23, 2023 26 minutes ago, Jos said: show the full code so we can see what you are doing and whether you are waiting long enough. dont understand why you need full code but there is I think problem in paramets for run() expandcollapse popupIf WinExists('[CLASS:AutoIt v3;TITLE:' & @ScriptName & ']') Or WinExists(@ScriptName & ".exe") Then ;MsgBox(48, @ScriptName, 'Позволено запускать только одну копию программы!' & @CRLF & @CRLF & 'ОК ==> ВЫХОД') Exit EndIf AutoItWinSetTitle(@ScriptName) TraySetToolTip(@ScriptName & " v1") #include <Array.au3> #include <Constants.au3> Local $Sleep_posle_vseh_beckapov = 4320;0000 $sOut = '' ; Переменная для хранения вывода StdoutRead. $file_name_dla_zapuska = "NEW_BD_backup.au3" $file_name_dla_zapuska = "NEW_BD_backup.exe" $k=0 While 1 ;For $i = 0 To 2 $iPID1 = Run("Autoit_errror.exe") ;$iPID = Run(FileGetShortName(@AutoItExe) & " /AutoIt3ExecuteScript " & FileGetShortName($file_name_dla_zapuska), @WorkingDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) $iPID = Run($file_name_dla_zapuska, @WorkingDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) ;$iPID = Run($file_name_dla_zapuska) ConsoleWrite("WinExists('Autoit_errror.exe')=" & WinExists('Autoit_errror.exe') & @CRLF) ;$iPID = Run(@ComSpec & ' /U /C DIR "' & $sPath & '\' & $sFileMask & '" /B /S /A-D', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;ConsoleWrite("$i =" & $i & @CRLF) $log_count = 0 $n = 0 While 1 $n = $n + 1 ;$sOut &= StdoutRead($iPID, False) $time = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC ConsoleWrite($time&" 1log posle =" & $n & " " & @error & @CRLF) ;ConsoleWrite("log posle =" & $sOut & @CRLF) Sleep(15000) If WinExists('[CLASS:AutoIt v3;TITLE:' & $file_name_dla_zapuska & ']') = 0 Then Sleep(1000) $sOut &= StdoutRead($iPID, False) Sleep(5000) $time = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC ConsoleWrite($time&" Console_logs_from_NEW_BD_backup =" & $sOut & @CRLF) If $log_count < 500 Then $hFile = FileOpen("Console_logs_from_NEW_BD_backup.txt", 1) Else $hFile = FileOpen("Console_logs_from_NEW_BD_backup.txt", 2) $log_count = 0 EndIf FileWrite($hFile, $time & @CRLF & $sOut & @CRLF & @CRLF & "=====================================================================================================================================================================" & @CRLF) FileClose($hFile) ExitLoop EndIf WEnd $k=$k+1 $time = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC ConsoleWrite($k&" "&$time&" Sleep_posle_vseh_beckapov start =" & $Sleep_posle_vseh_beckapov&" milliseconds" & @CRLF& @CRLF) Sleep($Sleep_posle_vseh_beckapov) WEnd ;Next Link to comment Share on other sites More sharing options...
nill Posted June 23, 2023 Author Share Posted June 23, 2023 (edited) After a little research, I realized that if you run it this way, it goes into the console $iPID = Run(file_name.exe, @WorkingDir, @SW_SHOW) but the output is not written to txt How do I make the logs in the console and then write them in txt? Edited June 23, 2023 by nill Link to comment Share on other sites More sharing options...
Developers Jos Posted June 23, 2023 Developers Share Posted June 23, 2023 Just look at the helpfile for a "simple" example of StdOutRead() because your code is not strait forward and has all kind of sleep() statements in it. Try it that way to see if it works. 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...
nill Posted June 23, 2023 Author Share Posted June 23, 2023 2 hours ago, Jos said: Just look at the helpfile for a "simple" example of StdOutRead() because your code is not strait forward and has all kind of sleep() statements in it. Try it that way to see if it works. I read about StdoutRead but still do not understand how sleep() relates to my question Link to comment Share on other sites More sharing options...
Developers Jos Posted June 23, 2023 Developers Share Posted June 23, 2023 Did you try the basic example with you program and did it work? 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...
nill Posted June 24, 2023 Author Share Posted June 24, 2023 I take this example from help file for autoit $iPID = Run(@ComSpec & ' /U /C DIR "' & $sPath & '\' & $sFileMask & '" /B /S /A-D', @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) as it is, it doesn't work, so I converted it to $iPID = Run($file_name_dla_zapuska, @WorkingDir, @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) and it works as I described above, can you just show me your working example? Link to comment Share on other sites More sharing options...
Musashi Posted June 24, 2023 Share Posted June 24, 2023 8 hours ago, nill said: can you just show me your working example? Try : #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 6 -w 7 #include <Constants.au3> Global $sCommand, $iPID, $iRetValue $sCommand = "net user " & @UserName $iPID = Run($sCommand, "", @SW_HIDE, BitOR($STDOUT_CHILD, $STDERR_CHILD)) $iRetValue = ProcessWaitClose($iPID) ConsoleWrite("RetValue = " & $iRetValue & @CRLF & _ "Command = " & $sCommand & @CRLF & @CRLF & _ "---------- OUTPUTREAD : ------------ " & @CRLF & _ StdoutRead($iPID) & @CRLF & _ "---------- ERRORREAD : ------------ " & @CRLF & _ StderrRead($iPID) & @CRLF) robertocm 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." 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