Jump to content

The TIMEOUT command run from a batch job exits immediately and returns?

Recommended Posts


#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>


Func Example()
    Local $sOutput = ""
Local $iPID = Run(@ComSpec & " /c " & 'timeout /t 10 & netsh wlan show interfaces' , "", @SW_HIDE, $STDERR_MERGED+$STDIN_CHILD)
     ; Local $iPID = Run('timeout /t 10 & netsh wlan show interfaces', "", @SW_HIDE, $STDERR_MERGED)
        $sOutput = StdoutRead($iPID)

        If $sOutput <> "" Then MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

    Until @error ; Exit the loop if the process closes or StdoutRead returns an error.

EndFunc   ;==>Example

The TIMEOUT command run from a batch job exits immediately and returns "ERROR: Input redirection is not supported, exiting the process?

Link to comment
Share on other sites

Seems like timeout.exe doesn't support Input or Output redirection. I say this because removing $STDIN_CHILD has no effect--still produces same error.  

Here is a "hack" to do the equivalent of "timeout /t 10", but perhaps resorting to using AutoIt sleep() would be just a well suited?

Local $iPID = Run(@ComSpec & " /c " & 'choice /t 10 /c ab /d a >nul & netsh wlan show interfaces' , "", @SW_HIDE, $STDERR_MERGED)


Edited by spudw2k
Link to comment
Share on other sites

Here a way to perform a MsgBox with no flicker and a count down :

#include <Constants.au3>

Global $iTimer


Func Example($iTime)
  Local $sCommand = ' /AutoIt3ExecuteLine "ConsoleWrite(MsgBox(' & $MB_OKCANCEL & ', ''Count Down'', ''Execution will start in ' & $iTime & ' secs'', ' & $iTime & '))"'
  Local $iPID = Run(@AutoItExe & $sCommand, "", @SW_SHOW, $STDERR_MERGED)
  $iTimer = $iTime
  AdlibRegister(CountDown, 1000)
  While ProcessExists($iPID)
  Local $iResp = StdoutRead($iPID)
  Switch $iResp
      ConsoleWrite("Time Out" & @CRLF)
    Case $IDOK
      ConsoleWrite("OK" & @CRLF)
    Case $IDCANCEL
      ConsoleWrite("Cancel" & @CRLF)

Func CountDown()
  $iTimer -= 1
  ControlSetText("Count Down", "", "Static1", "Execution will start in " & $iTimer & " secs")


Link to comment
Share on other sites

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