Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Introduction

The Windows timeout.exe command can be used to delay execution of subsequent commands for an arbitrary duration specified by 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 they cannot 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:

Code Block
titleExamples Example for use mapping of emulated timeout commandlinenumberstrue.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 duration command corresponds to approx. 3+1 ping executions. The ping command implements a delay of 1 seconds 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 scripts script maps the timeout.exe command and its parameters to use of the ping command:

...

Code Block
titleExamples for use of emulated timeout command
linenumberstrue
@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

Making timeout.cmd a Windows Executable timeout.exe


In a second step To convert the above batch script to an executable file timeout.exe using 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 use 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 ./bin/<AGENT_HOME>\bin\agent_4445.cmd, prioritize the Agent’s .\bin directory with the Windows PATH environment variable usinglike this:

Code Block
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 first.