简体   繁体   English

在自己的cmd.exe中运行工具

[英]Running a tool in its own cmd.exe

I am working on a Java application which will be used to launch other applications. 我正在研究将用于启动其他应用程序的Java应用程序。 Now, most of those have a GUI, but some are command-line tools. 现在,大多数工具都具有GUI,但是有些工具是命令行工具。 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. 也就是说,在Windows上,我想打开cmd.exe,并使用适当的参数运行该工具。 The problem is getting cmd.exe to stay open. 问题是使cmd.exe保持打开状态。

When I use ProcessBuilder to start 当我使用ProcessBuilder启动时

cmd.exe /k java -version

I get the desired output (I capture the output streams), but the cmd.exe window isn't visible. 我得到了所需的输出(捕获了输出流),但是cmd.exe窗口不可见。

When I run 当我跑步

cmd.exe /k start java -version

the cmd.exe window pops up for a split second and then disappears. cmd.exe窗口会突然弹出,然后消失。

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). 但是,当我只运行cmd.exe /k start ,cmd.exe窗口就会出现并保持打开状态,而cmd.exe start不会显示一个窗口(正如我期望的那样)。

What I want is for the command line tool to run in its own cmd.exe and stay open for input. 我想要的是让命令行工具在其自己的cmd.exe中运行并保持打开状态以供输入。

Running this from the cmd.exe works. 从cmd.exe运行此程序。

cmd start cmd /k java -version

However, this just waits for you to run more cmd's. 但是,这只是等待您运行更多的cmd。

If you want it to wait for user input use 如果希望它等待用户输入使用

cmd start java MyProgramWhichWaitsForInput

This was solved using the answer in "Starting a Java tool with cmd.exe" . 使用“使用cmd.exe启动Java工具”中的答案解决了该问题。 I suspected the problems were separate, but they were not. 我怀疑问题是分开的,但不是分开的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM