You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Introduction

The Windows timeout 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 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 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 command is designed for interactive use by a user, not for execution in batch mode.
    • The timeout 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 command.
    • As JS7 Agents do not dispose of a keyboard they cannot 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 command:

Examples for use of emulated timeout command
# equivalent commands

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

Explanation:

  • A 3 seconds timeout.exe duration corresponds to approx. 3+1 ping executions. The ping command implements a delay of 1 seconds 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 commands in existing batch scripts that cannot easily be replaced by ping commands are offered the below solution.

Solution

Replacing timeout.exe Command by a timeout.cmd Batch Script

The following Windows batch script is used to emulate the timeout command. The scripts maps the timeout 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

Making timeout.cmd a Windows Executable timeout.exe

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

Updating Windows PATH Environment Variable from the Agent Instance Start Script

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

In the Agent Instance Start Script, for example ./bin/agent_4445.cmd, prioritize the Agent’s .\bin directory with the Windows PATH environment variable using:

set PATH=%~dp0;%PATH%

As a result any call to the timeout.exe executable from a job script will first be looked up from the Agent's ./bin directory.



  • No labels