Introduction

The Windows timeout.exe command can be used to delay execution of subsequent commands for an arbitrary duration specified ín seconds. However, the command cannot be used in JS7 job scripts:

  • Use of the timeout.exe command results in the job error: 
    • English: 2024-04-22 22:30:41.513+0200 [STDERR]  ERROR: Input redirection is not supported, exiting the process immediately.
    • French: 2024-04-22 22:30:41.513+0200 [STDERR]  Erreur : la redirection de l'entrée n'est pas prise en charge. Fin immédiate du processus.
    • German: 2024-04-22 22:30:41.513+0200 [STDERR]  FEHLER: Die Eingabeumleitung wird nicht unterstützt. Prozess wird unverzüglich beendet. 
  • The reason being that the timeout.exe command implements redirection of the stdin channel from an input device such as a keyboard that is expected to be attached the process. In fact the timeout.exe command is designed for interactive use by a user, not for execution in batch mode.
    • The timeout.exe command offers the /nobreak option to prevent interruption from a number of keyboard events. However, this does not change input redirection and allows a user to hit CTRL+C from the keyboard to interrupt the timeout.exe command.
    • As JS7 Agents run in unattended mode they do not dispose of a keyboard which denies to execute a Windows command that implements redirection from a keyboard.

The recommended solution is to use the ping command as a replacement for the timeout.exe command:

Example for mapping of timeout.exe command to ping command
# equivalent commands

timeout.exe /t 3
ping -n 4 127.0.0.1 > nul

Explanation:

  • A duration of 3 seconds with the timeout.exe command corresponds to approx. 3+1 ping executions. The ping command implements a delay of 1 second between retries.
  • Use of the IP address 127.0.0.1 is required as the address is guaranteed to query the local host and not to raise DNS errors.

Users who find timeout.exe commands in existing batch scripts that cannot easily be replaced by ping commands are offered the below solution.

Solution

Replacing the Windows timeout.exe Command

The solution implements a version of the timeout.exe command that is compliant to unattended batch mode without input redirection as used by JS7:

  • users can download the compliant version of timeout.exe.
  • or
  • users can create their own version of timeout.exe.

Download

Download the replacement for the Windows timeout.exe command: timeout.exe

Store the downloaded file to the Agent's <AGENT_HOME>\bin directory.

Creating timeout.exe from a timeout.cmd Batch Script

Users can create their own version of timeout.exe instead of downloading the above version of the file.

The following Windows batch script is used to emulate the timeout.exe command. The script maps the timeout.exe command and its parameters to use of the ping command:

Emulation of Windows timeout command
@echo off
@setlocal

:read_command_line_options
if "%~1" == "" goto read_command_line_options_end
if /I "%~1" == "/T" (
    set /A "seconds=%~2+1"
    goto read_command_line_options_end
)
shift
goto read_command_line_options
:read_command_line_options_end

ping -n %seconds% 127.0.0.1 > nul
@endlocal
goto :eof


If the above script is stored to a timeout.cmd batch file, then it can be executed like this:

Examples for use of emulated timeout command
@rem The following commands are mapped to use of:
@rem ping -n 4 127.0.0.1 > nul

timeout.cmd /t 3

timeout.cmd /T 3

timeout.cmd /T 3 /nobreak

timeout.cmd /nobreak /T 3


To convert the above batch script to an executable file timeout.exe use for example https://github.com/islamadel/bat2exe/ (any other tool will do).

Updating Windows PATH Environment Variable from the Agent Instance Start Script

For use at run-time copy the downloaded or newly created timeout.exe file to the Agent’s <AGENT_HOME>\bin directory.

In the Agent Instance Start Script, for example <AGENT_HOME>\bin\agent_4445.cmd, prioritize the Agent’s .\bin directory with the Windows PATH environment variable like this:

rem set JAVA_OPTIONS=
rem set JOB_JAVA_OPTIONS=

set PATH=%~dp0;%PATH%

Explanation:

  • The PATH environment variable is updated in the Agent Instance Start Script after any other environment variables are declared.
  • As a result any call to the timeout.exe executable from a job script will first be looked up from the Agent's <AGENT_HOME>\bin directory.



  • No labels