Jump to content

Recommended Posts

Posted
35 minutes ago, Jos said:

Yes I did and was just playing a little... ;)

;)

It wasn't me who started with While-Loops, that has already happened in some of the previous posts. My script should only illustrate the problem to the OP without opening 1000+ CMD windows (but you already know that).
True to the motto : "Helping people to help themselves"
Sometimes the line between helping, confusing and feeding is blurred.
But you're probably right - In the end, it may have misdirected the user's focus :lol:.

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

Posted
On 11/29/2019 at 2:10 AM, boy15 said:

I want run script after 15 sec every time

You wanna run a batch file, so, why not just do all the code in the batch file ?. What do you wanna get done with this ?. Not knowing how you wrote the batch file, I can not even say "use the PID". If you were to post a working ( or attempted ) code, and what you wanna get done, we all can give you better aid :) 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • 5 years later...
Posted

Everyone seems very patient in teaching OP but it doesn't seem to be working.

@boy15 This script is definitely what you want:

#RequireAdmin

; This flag is used to enable the console window when compiling.
#AutoIt3Wrapper_Change2CUI=y
#pragma compile(Console, true) 


Opt("MustDeclareVars", 0) ;0=no, 1=require pre-declaration
Opt("TrayAutoPause", 0) ;0=no pause, 1=Pause
HotKeySet("{ESC}", "_Exit") ; *** just to have an option to quit

Global $g_iTimeRun = 30
Global $g_sFilename = @TempDir & "\anyname.bat"
Global $g_bOnRuning = False
WinSetTitle(@ScriptFullPath, '', 'Program automatically runs BAT file every 30s')
ConsoleWrite("+ Program running ! Press ESC to Exit" & @CRLF)
AdlibRegister('_RunCmd_File', $g_iTimeRun * 1000)
_RunCmd_File() ; run it the first time

While 1 ; keep the program running
    Sleep(100)
WEnd

Func _RunCmd_File()
    If $g_bOnRuning Then Return
    If Not FileExists($g_sFilename) Then _FileInstall_BatFile()
    If FileExists($g_sFilename) Then
        $g_bOnRuning = True
        ConsoleWrite("> RUN: " & $g_sFilename & " " & @CRLF)
        _RunCmd_GetOutput($g_sFilename)
    EndIf
    $g_bOnRuning = False
EndFunc   ;==>_RunCmd_File

Func _FileInstall_BatFile()
    FileInstall("Anyname.bat", $g_sFilename, 1)
    If FileExists($g_sFilename) Then
        ConsoleWrite("> Successfully installed bat file to:: " & $g_sFilename & " " & @CRLF)
    Else
        ConsoleWrite("! Error installing bat file to: " & $g_sFilename & " " & @CRLF)
        ConsoleWrite("! Paused. Will try again in " & $g_iTimeRun & "s" & @CRLF)
    EndIf
EndFunc   ;==>_FileInstall_BatFile

Func _Exit()
    ConsoleWrite("! The script was terminated by the user. (Hotkey)" & @CRLF)
    Exit
EndFunc   ;==>_Exit

Func _RunCmd_GetOutput($sCommand)
    ConsoleWrite("+Execute: " & $sCommand & @CRLF)
    Local $sOutput = '', $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, '', @SW_HIDE, 0x6)
    Do
        $sOutput &= StdoutRead($iPID)
    Until @error
    Do
        $sOutput &= StderrRead($iPID)
    Until @error
    ConsoleWrite($sOutput & @CRLF)
    Return $sOutput
EndFunc   ;==>_RunCmd_GetOutput

 

Enjoy my work? Buy me a 🍻 or tip via ❤️ PayPal

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