在Windows CMD,我怎么提示用户输入而在另一个命令中使用的结果呢? [英] In Windows cmd, how do I prompt for user input and use the result in another command?

查看:481
本文介绍了在Windows CMD,我怎么提示用户输入而在另一个命令中使用的结果呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows .BAT,我愿意接受用户的输入,然后使用该输入的结果调用其他命令的一部分文件。

例如,我愿意接受来自用户的进程ID,然后运行jstack针对该ID,投入的结果jstack调用到一个文件中。然而,当我试试这个,这是行不通的。

下面是我的样品批处理文件的内容:

 关闭@echo
集/ p = ID输入ID:
回声%ID%
jstack> jstack.txt

和这里的jstack.txt显示的内容:


输入ID:终止批处理作业(Y / N)?


解决方案

试试这个:

 关闭@echo
集/ p ID =输入ID

您可以再使用%ID%作为参数传递给另一个批处理文件。例如:

  jstack%ID%

编辑:这只是正常的我。对不起,我不能帮助更多。

 设定/ p = ID输入ID:
jstack%ID%GT; 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. 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

这篇关于在Windows CMD,我怎么提示用户输入而在另一个命令中使用的结果呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆