Jump to content

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


Recommended Posts

image.thumb.png.04120e05b5483eb055c33a067d24bea1.png

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

Example()

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)
    ProcessWaitClose($iPID,15000)
    Do
        $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

Example(10)

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)
    Sleep(50)
  WEnd
  AdlibUnRegister(CountDown)
  Local $iResp = StdoutRead($iPID)
  Switch $iResp
    Case $IDTIMEOUT
      ConsoleWrite("Time Out" & @CRLF)
    Case $IDOK
      ConsoleWrite("OK" & @CRLF)
    Case $IDCANCEL
      ConsoleWrite("Cancel" & @CRLF)
  EndSwitch
EndFunc

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

 

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...