In Windows cmd, how do I prompt for user input and use the result in another command? In Windows cmd, how do I prompt for user input and use the result in another command? windows windows

In Windows cmd, how do I prompt for user input and use the result in another command?


Try this:

@echo offset /p id="Enter ID: "

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

For example:

set /P id=Enter id: jstack %id% > jstack.txt


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.

@echo offset /p UserInputPath=What Directory would you like?cd C:\%UserInputPath%

note the %VariableName% syntax


set /p choice= "Please Select one of the above options :" echo '%choice%'

The space after = is very important.