在自己的 cmd.exe 中运行工具
我正在开发一个 Java 应用程序,它将用于启动其他应用程序。现在,其中大多数都有 GUI,但有些是命令行工具。对于后者,我想打开适当的命令行并让它们在那里执行。
也就是说,在 Windows 上,我想打开 cmd.exe,并使用适当的参数运行该工具。问题是让 cmd.exe 保持打开状态。
当我使用 ProcessBuilder 启动时,
cmd.exe /k java -version
我得到了所需的输出(我捕获输出流),但 cmd.exe 窗口不可见。
当我运行
cmd.exe /k start java -version
cmd.exe 窗口时,会突然弹出然后消失。
但是,当我刚刚运行 cmd.exe /k start
时,cmd.exe 窗口会出现并保持打开状态,而 cmd.exe start
不会显示窗口(正如我所希望的那样)预计)。
我想要的是命令行工具在自己的 cmd.exe 中运行并保持打开状态以供输入。
I am working on a Java application which will be used to launch other applications. Now, most of those have a GUI, but some are command-line tools. For the latter, I would like to open the appropriate command line and have them execute there.
That is, on Windows, I would like to open cmd.exe, and run the tool with the appropriate arguments. The problem is getting cmd.exe to stay open.
When I use ProcessBuilder to start
cmd.exe /k java -version
I get the desired output (I capture the output streams), but the cmd.exe window isn't visible.
When I run
cmd.exe /k start java -version
the cmd.exe window pops up for a split second and then disappears.
But when I just run cmd.exe /k start
the cmd.exe window appears and stays open, while cmd.exe start
doesn't show a window (as I would expect).
What I want is for the command line tool to run in its own cmd.exe and stay open for input.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 cmd.exe 运行它是有效的。
但是,这只是等待您运行更多 cmd。
如果你想让它等待用户输入使用
Running this from the cmd.exe works.
However, this just waits for you to run more cmd's.
If you want it to wait for user input use
使用 “使用 cmd.exe 启动 Java 工具”< 中的答案解决了这个问题/a>.我怀疑这些问题是独立的,但事实并非如此。
This was solved using the answer in "Starting a Java tool with cmd.exe". I suspected the problems were separate, but they were not.