Windows Batch File Prompt For Input

  1. Feb 15, 2019  On Windows 10, a batch file is a special kind of text file that typically uses a.bat extension, which can include one or multiple commands that Command Prompt can understand and run in.
  2. Jan 25, 2009  Making Y/N questions in batch files. Welcome guest. Before posting on our computer help forum, you must register. /P - Prompt the user with the question that follows and set the answer to the variable. Logged PirateSamir. I want a batch file that will ask you yes or no questions and the only buttons that will wield you a result.

Simple user input in batch files. I was recently playing around with batch scripts (.bat files) - but what I wanted to do with the script snowballed and I found I needed more functionality, the main one being to be able to execute commands based on user input.

Active2 years, 1 month ago

This question already has an answer here:

  • How to run a batch file without launching a “command window”? [duplicate] 9 answers

I have installed a ruby gem called Redcar, which is launched from the command line. When it runs, it steals the shell until it terminates, so I have to create a new shell window to continue doing command line work. The shell I'm using is the GITBash shell from MySysGit.

I found a Redcar.bat file which is meant to launch Redcar as a shortcut, I presume, but I don't want the extra command prompt window to open whenever I launch the BAT file.

How do I just run the BAT without seeing the prompt?

Simon Sheehan
7,79612 gold badges45 silver badges69 bronze badges
JakeJake

marked as duplicate by fixer1234, DavidPostill windowsOct 7 '16 at 10:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

13 Answers

You can't -- executing a batch file with the built in Command Prompt is going to keep a window open until the batch file exits.

What you can do is take steps to make sure that the batch file exits as quickly as possible. If at all possible, modify the batch file to run whatever program with the start command. By default, start returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately. Couple that with modifying your shortcut to run the batch file minimized, and you'll only see the taskbar flash without even seeing a window onscreen.

One caveat to this is that if you're running a console-mode program, which many script interpreters are, the batch file will wait for the program to exit, and using start will spawn a new console window. What you need to do in this case is run the Windows-based version of the interpreter instead of the console-based one -- no start necessary. For Perl, you would run wperl.exe instead of perl.exe. For Python, it's pythonw.exe instead of python.exe. The old win32 Ruby distribution I have downloaded has rubyw.exe, which should do the same thing.

A final possibility is to use a 3rd-party tool to run the command prompt with a hidden window. I've heard of such things but never had a use for them, so I don't know of anything in particular to point you to.

afrazierafrazier
21.1k2 gold badges49 silver badges82 bronze badges

I think this is the easiest and shortest solution to running a batch file without opening the DOS window, it can be very distracting when you want to schedule a set of commands to run periodically, so the DOS window keeps popping up, here is your solution.Use a VB Script to call the batch file ..

Copy the lines above to an editor and save the file with .VBS extension. Edit the .BAT file name and path accordingly.Then just run the .vbs file and the magic happens!

indagoindago

You can run another batch file with START /MIN CMD.EXE /C mybatchfile.bat from within the command prompt.

From outside it will bring the cmd console window but to avoid that, you can create a shortcut file with properties modified to start minimized.

vhanlavhanla

To do this, use the program Bat To Exe Converter to convert your batch file to an executable file.

When converting into an executable, you will find an option to run your file as an Invisible application in the visibility section. Thus, when you run it, it will run without a window.

Don't Root here plz..Don't Root here plz..
1,6361 gold badge11 silver badges38 bronze badges

Continuing on Dennis Williamson's answer, you can edit the batch file and append (prepend) START /B to the command you are executing.

For example, I have a batch file that runs putty and had the same problem (extra CMD),so this is how I wrote it:

It worked perfectly.

Scott
17.3k11 gold badges48 silver badges92 bronze badges
Adonis DarwishAdonis Darwish

Give this a try:

note added by barlop

start /? says of /B

barlop
16.1k26 gold badges92 silver badges155 bronze badges
Dennis WilliamsonDennis Williamson
82.3k16 gold badges137 silver badges170 bronze badges

I'm not clear as to your issue, but with some of my batch files, I use a 'dumy' who's only purpose is to launch the main batch file.

So GO.BAT will have:

The exit closes the command prompt window that would otherwise remain open.

And GO2.BAT will have the actually batch file contents that I wish.

Sathyajith Bhat
53.8k30 gold badges160 silver badges254 bronze badges
therubetherube
Jens A. KochJens A. Koch

If you are still interested in not showing the console window at all, here is a solution from stackoverflow that worked for me(in my case I didn't put anything in the registry, but where I needed).

Community
raviolliraviolli

Just put the /b switch in front of the path. It won't open the second command prompt.

JesseJesse

Indago's answer has been the best solution for me so far. The VBS file allows me to run the batch's functionality through the script, preventing the CMD window from happening in the first place. There are a few caveat's though:

  1. If your batch requires admin rights, create or use an existing batch that calls the VBS and run that batch as Administrator.

  2. With no visibiity, it can be difficult to discern if what you're trying to do is actually running the way you want it to.

With that said, I'd put a little mock set-up/unit test up first to make sure it's working exactly the way you want it to, before integrating it.

Community
kayleeFrye_onDeckkayleeFrye_onDeck

I've used cmdow in the past, and it seems to have worked for what I want.

You'll probably want to use one of the following options:CMDOW [window] /HID

Essentials of physical anthropology pdf. Essentials of Physical Anthropology. With a brand new framework that emphasizes ’connections’, the reader is proven how people are biologically related to all different life, together with our distant ancestors and our modern primate cousins, in addition to how intently trendy human populations.

/HID hides the specified window

CMDOW [window] /END

/END closes the specified window

CMDOW [window] /CLS

/CLS politely asked the window to close (some windows may open a dialogue box)

Hope this helps.

sonrad10sonrad10

Just make a shortcut to the batch file, right click on it, click on Properties, go to General tab, check the box called Hidden, click on Apply and then on OK.
Now as you open the shortcut it will run the batch file Hidden.

MagicalDiamondsMagicalDiamonds

Not the answer you're looking for? Browse other questions tagged windowscommand-linebatch or ask your own question.

Active4 months ago

I have a Windows .bat file which I would like to accept user input and then use the results of that input as part of the call to additional commands.

For example, I'd like to accept a process ID from the user, and then run jstack against that ID, putting the results of the jstack call into a file. However, when I try this, it doesn't work.

Here's my sample bat file contents:

and here's what shows up in jstack.txt:

NakilonFor
28.5k12 gold badges88 silver badges115 bronze badges
marc

12 Answers

Try this:

You can then use %id% as a parameter to another batch file like jstack %id%.

For example:

ashleedawg
13.8k4 gold badges29 silver badges62 bronze badges
InstantsoupInstantsoup
12.3k5 gold badges31 silver badges41 bronze badges

The syntax is as such: set /p variable=[string]

Check out http://commandwindows.com/batch.htm or http://www.robvanderwoude.com/userinput.php for a more deep dive into user input with the different versions of Windows OS batch files.

Once you have set your variable, you can then go about using it in the following fashion.

note the %VariableName% syntax

Zitrax
9,71213 gold badges70 silver badges83 bronze badges
jayfessendenjayfessenden

I am not sure if this is the case for all versions of Windows, however on the XP machine I have, I need to use the following:

Without the prompt string in quotes, I get various results depending on the text.

Erik Philips
43.4k6 gold badges100 silver badges132 bronze badges
DanielDaniel
Grimthorr
4,8995 gold badges26 silver badges40 bronze badges
hannad rehmanhannad rehman

if i get what you want, this works fine. you can use %input% in other commands too.

Eamorr
5,38729 gold badges103 silver badges191 bronze badges
fedebfedeb
Anisha GuptaAnisha Gupta

There is no documented /prompt parameter for SETX as there is for SET.

If you need to prompt for an environment variable that will survive reboots, you can use SETX to store it.

A variable created by SETX won't be usable until you restart the command prompt. Neatly, however, you can SETX a variable that has already been SET, even if it has the same name.

This works for me in Windows 8.1 Pro:

(The quotation marks around the existing variable are necessary.)

Ricoh mp c3500 driver. This procedure allows you to use the temporary SET-created variable during the current session and will allow you to reuse the SETX-created variable upon reboot of the computer or restart of the CMD prompt.

(Edited to format code paragraphs properly.)

Timothy J. McGowanTimothy J. McGowan

I have a little cmd I use when preparing pc to clients: it calls the user for input, and the rename the pc to that.

WerdnaWerdna

There are two possibilities.

  1. You forgot to put the %id% in the jstack call.

Dos Batch Files Commands

So the whole correct batch file should be:

And/Or 2. You did put it in the code (and forgot to tell us in the question) but when you ran the batch file you hit the Enter key instead of typing an ID (say 1234).

What's happening is the result of these two mistakes: jstack is supposed to be called with the id that you supply it.

Dreamcast roms download. The Sega Dreamcast in assembly already included a modem or network adapter for the Internet, and among the programs for the console appeared a browser. The development was attended by famous world leaders such as Hitachi, Microsoft, Video Logic, Nec and Yamaha. For the firmware was chosen operating system Windows CE.

But in your case (according to the code you supplied in the question) you called it without any variable. You wrote:

So when you run jstack with no variable it outputs the following:

Your second mistake is that you pressed Enter instead of giving a value when the program asked you: Enter ID:. If you would have put in an ID at this point, say 1234, the %id% variable would become that value, in our case 1234. But you did NOT supply a value and instead pressed Enter. When you don't give the variable any value, and if that variable was not set to anything else before, then the variable %id% is set to the prompt of the set command!! So now %id% is set to Enter ID: which was echoed on your screen as requested in the batch file BEFORE you called the jstack.

But I suspect you DID have the jstack %id% > jstack.txt in your batch file code with the %id (and omitted it by mistake from the question), and that you hit enter without typing in an id. The batch program then echoed the id, which is now 'Enter ID:', and then ran jstack Enter ID: > jstack.txt

Jstack itself echoed the input, encountered a mistake and asked to terminate.
And all this was written into the jstack.txt file.

pashutepashute

Dollar signs around the variable do not work on my Vista machine, but percent signs do.Also note that a trailing space on the 'set' line will show up between the prompt and user input.

SRESRE

Just added the

sequence to my netsh batch job. It now shows me the location I respond as the point for that sample. I continuously >> the output file so I know now 'home', 'work', 'Starbucks', etc. Looking for clear air, I can eavulate the lowest use channels and whether there are 5 or just all 2.4 MHz WLANs around.

ElektroStudios
7,87926 gold badges124 silver badges307 bronze badges
JohnJohn

Just to keep a default value of the variable. Press Enter to use default from the recent run of your .bat:

Batch File Wait For Enter

In the first run just ignore the message about lack of file with the initial value of the variable (or do create the Var1.txt manually).

Bat File Variable Input

AntoniAntoni