Home > Software design >  How does one close stdin from the windows CMD prompt?
How does one close stdin from the windows CMD prompt?

Time:05-07

I know that one can close stdin when executing a command from a Linux CLI using logic such as:

0<&- <command>

This simulates/emulates running an application unattended, or within a CI/CD system such as Jenkins/Gitlab that has stdin closed.

Why do I care? Because we have an application that has a "Press any key to continue..." prompt.

When run under Jenkins/Gitlab or anything that doesn't have stdin open, it just moves on..... when run on Linux.

How would I do this, and is this possible to do this from the Windows CMD Window CLI?

I've tried 0<&- and that results in the message

0<& was unexpected at this time.

Google search gives many hits for stdin but all the documentation is on redirection. I haven't found anything for windows for closing.

CodePudding user response:

You can try

command <nul

which basically means "take any input from the NUL device (as an infinite source of "CRLF"'s). This works as long as command takes its input from STDIN (like the pause command) and doesn't flush the input buffer (like the choice command)

If you need textual input (like the set /p command), you need another approach:

echo inputtext|command 
  • Related