Jump to content

Recommended Posts

Posted
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()

If 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


 

Posted (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 by nill
  • Developers
Posted

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.
  :)

Posted
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

Posted

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?

Posted
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)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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...