24

This is the code I want to launch with Jenkins :

start cmd.exe /k "node "C:\Program Files\Appium\node_modules\appium\bin\appium.js" -a 127.0.0.1 -p 4723"
ping 127.0.0.1 -n 30 > nul
C:\path\NUnit-2.6.4\NUnit-2.6.4\bin\nunit-console.exe C:\path\NUnit-2.6.4\NUnit-2.6.4\bin\apk\UnitTestProject1.dll

This is the error I get every time I try to put a pause:

"ERROR: Input redirection is not supported, exiting the process immediately."

Same error with timeout /T 60 and sleep 60

According to this post , timeout does not work in non-interactive scripts.

How can I add a pause in my situation ?

Edit for Will Ryan :

I try this :

enter image description here

The build worked, but the test duration is only 0.5 seconds, the pause doesn't do anything

enter image description here

The console output is :

C:\Program Files\Jenkins\jobs\ZFAIL\workspace>echo "--" 
"--"

C:\Program Files\Jenkins\jobs\ZFAIL\workspace>PING 1.1.1.1 -n 1 -w 30000  1>NUL 

C:\Program Files\Jenkins\jobs\ZFAIL\workspace>echo "++" 
"++"

C:\Program Files\Jenkins\jobs\ZFAIL\workspace>exit 0 
Finished: SUCCESS
Community
  • 1
  • 1
CE_
  • 954
  • 2
  • 12
  • 29
  • 1
    Does `choice /T 60` work? – Christopher Orr Aug 31 '15 at 10:17
  • No, `incorrect syntax : /T cannot be specified without /D` – CE_ Aug 31 '15 at 11:24
  • 1
    Ok, so does it work with `/D`? You can just ignore the output of the choice, right? – Christopher Orr Aug 31 '15 at 12:24
  • I try `choice /C YN /T 60 /D Y`, but it still doesn't work with Jenkins – CE_ Aug 31 '15 at 12:36
  • Yay, Windows. I guess you could write a node script that sleeps for you, and execute that? e.g. `require('sleep').sleep(60)` – Christopher Orr Aug 31 '15 at 13:38
  • 1
    @CE_ Why do you start `node` with `appium.js` in a new and separate command process with keeping this command process open after `node` finished if you need to wait with `nunit-console.exe` execution until `node` finished? – Mofi Aug 31 '15 at 13:41
  • @Mofi Because when I launch the server with the Windows Cmd, I can't use the CMD anymore for something else. In Jenkins,it result as an infinite loop. Same case when i launch the emulator, I need to wait him to launch ~60s before doing something else – CE_ Aug 31 '15 at 13:56
  • I suppose the -w option only comes to effect if there is no response. From Wikipedia 1.1.1.1 is a "free Domain Name System". You should provide an ip than is not answering. – grenix Jan 29 '20 at 11:07

6 Answers6

37

I think you can use the following command in Execute Windows batch command (will wait for 100 seconds):

waitfor SomethingThatIsNeverHappening /t 100 

This will return an error which could break your build. To avoid that, redirect the error output:

waitfor SomethingThatIsNeverHappening /t 100 2>NUL
Peter
  • 12,705
  • 10
  • 68
  • 105
Yauheni Basalai
  • 394
  • 2
  • 3
  • 1
    ` parallel( 'say hello': { println 'Hello in parallel' s.bat "timeout /t 10 2>NUL"//"waitfor SomethingThatIsNeverHappening /t 10 2>NUL" println 'sorry I took a nap' }, 'say ola': { println 'ola in parallel' } )` I get this ` ERROR: script returned exit code 1 ` – old-monk May 29 '18 at 18:34
  • 5
    @old-monk See if you can run this as command `waitfor SomethingThatIsNeverHappening /t 10 2>NUL || type nul>nul` :) – Jay Jun 02 '18 at 09:16
  • @old-monk thanks so much, if you want to use 2 pauses this is the way. – Merlyn007 Nov 25 '20 at 09:24
10

You can use this:

PING 1.1.1.1 -n 1 -w 30000 >NUL

This send one ping attempt and waits 30 seconds for a response. Not sure why you're getting the "ERROR: Input redirection is not supported, exiting the process immediately." message but I actively use the command above regularly.

Will Ryan
  • 601
  • 1
  • 7
  • 17
  • Can you try taking away the 1>nul and see what happens? – Will Ryan Sep 04 '15 at 12:59
  • You could also try the timeout command "timeout 30 > NUL" (obvoiusly without the quotes) That creates a countdown. – Will Ryan Sep 04 '15 at 13:04
  • 4
    `PING 1.1.1.1 -n 1 -w 30000 >NUL` only wait for 1 sec because it sends just one request, i manage to wait 60seconds with `PING 1.1.1.1 -n 60 > nul` – CE_ Sep 04 '15 at 13:07
  • `PING 127.0.0.1` doesn't work but `PING 1.1.1.1` work, really strange but thanks for the tip – CE_ Sep 04 '15 at 13:09
  • 2
    @ Will Ryan: Timeout doesn't run non-interactively properly - you get the 'Input redirection is not supported' message that OP mentioned. WAITFOR is another good alternative (i prefer to use it than PING personally). – WiredEarp Apr 27 '16 at 02:01
  • I know this is a very old post but the `-w` only applies for something that would timeout. Meaning for this to work that IP can never possibly respond. Since 1.1.1.1 is in use again you can update your script to do `ping 1.1.1.2 -n 1 -w 30000>NUL` – Patrick Helms Feb 24 '20 at 21:21
5

In case you want to get rid of the error message from Yauheni Basalai's answer, try sending the stderr to stdout by adding >nul 2>&1

waitfor SomethingThatIsNeverHappening /t 100 >nul 2>&1

credit goes to http://brisray.com/computers/batch-delay.htm

bwang
  • 86
  • 1
  • 2
0

I have encountered a similar problem with VSTS "command line" utility (v 2.*) which uses the cmd shell, and I have used the following (from elevated PowerShell session):

Add-Content c:\windows\sleep.cmd "call powershell -NoProfile -ExecutionPolicy ByPass -command sleep %1"
Jules Clements
  • 300
  • 2
  • 7
  • Sorry, that wasn't very clear. The above creates sleep.cmd, which means I can use the same command in PowerShell and cmd shell, i.e. `sleep 30` to sleep for 30 seconds – Jules Clements Dec 29 '17 at 19:32
0

Regarding the original PING approach

I suppose the -w option only comes to effect if there is no response. From Wikipedia 1.1.1.1 is a "free Domain Name System ... ". You should provide an ip to a host than is not online or is not answering ping requests. Adresses like 127.x.x.x are afaik loopback adresses that always answer.

>nslookup 1.1.1.1
....
Name:    one.one.one.one
Address:  1.1.1.1

>ping 1.1.1.1

Ping wird ausgeführt für 1.1.1.1 mit 32 Bytes Daten:
Antwort von 1.1.1.1: Bytes=32 Zeit=6ms TTL=58
...

As for credit goes to http://brisray.com/computers/batch-delay.htm:

@@@@

For an address that does not exist, such as 1.1.1.1 then use:

Ping 192.0.2.2 -n 1 -w 10000 > nul

In this case -n 1 means just one packet instead of 4 are sent and -w 10000 is the timeout in milliseconds.

@@@@

By the time the brishray.com article was written, there really was no 1.1.1.1 server alive. Interesting though that in the example 192.0.2.2 is used instead of 1.1.1.1. Anyhow its a matter of luck that the private IP 192.0.2.2 is not pingable. Nowadays e.g. "Ping nasa.gov -n 1 -w 10000 > nul" would do, but for how long and what if DNS fails...

In the end for now the answers with "waitfor" windows command have my highest sympathy

https://stackoverflow.com/a/43878566/2623045

https://stackoverflow.com/a/33368601/2623045

However its a windows feature, while it rather should be a Jenkins feature.

grenix
  • 498
  • 5
  • 11
0

According to this eclipse bug post , TIMEOUT in Windows batch has some sort of limitation and cannot be used in "background scripts".

The Assignee David Williams also said that 'PING' can be used instead, you may also notice that other choices are available, such as 'waitfor'.

I happened to encounter the same problem, and I chose GnuWin32 version sleep at last. In this scene, only coreutils will be enough. It uses the same unit (second) when counting.

Steven Liang
  • 158
  • 2
  • 8