views:

1271

answers:

1

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:

@echo off
set /p id=Enter ID: 
echo %id%
jstack > jstack.txt

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

Enter ID: Terminate batch job (Y/N)? 

Can someone help a complete cmd n00b?

Thanks a lot.

+1  A: 

Try this:

@echo off
set /p id=Enter ID: %=%

You can then use %id% as a parameter to another batch file. For example:

jstack %id%

EDIT: This works just fine for me. Sorry I can't help more.

set /P id=Enter id: %=%
jstack %id% > jstack.txt
Instantsoup
Thanks Instantsoup. I tried that, but I get the same result.