在 Windows cmd 中,如何提示用户输入并在另一个命令中使用结果? [英] In Windows cmd, how do I prompt for user input and use the result in another command?
问题描述
我有一个 Windows .bat 文件,我想接受用户输入,然后将该输入的结果用作调用其他命令的一部分.
例如,我想接受来自用户的进程 ID,然后针对该 ID 运行 jstack,将 jstack 调用的结果放入一个文件中.但是,当我尝试此操作时,它不起作用.
这是我的示例 bat 文件内容:
@echo offset/p id=输入 ID:回声%id%jstack >jstack.txt
这是 jstack.txt 中显示的内容:
<前>输入 ID:终止批处理作业 (Y/N)?试试这个:
@echo offset/p id="输入 ID:"
然后您可以使用 %id%
作为另一个批处理文件的参数,例如 jstack %id%
.
例如:
set/P id=输入id:jstack %id% >jstack.txt
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)?
Try this:
@echo off
set /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
这篇关于在 Windows cmd 中,如何提示用户输入并在另一个命令中使用结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!