[英]Create command line with echo off
I've read some articles on this subject, but I've been having troubles executing it myself. 我已经阅读了一些有关此主题的文章,但是我自己执行该代码时遇到了麻烦。 I'm trying to create a program that creates a command line with echo off, and this is the command I'm using at the moment:
我正在尝试创建一个程序,该程序创建一个带有回显功能的命令行,这是我目前正在使用的命令:
Runtime.getRuntime().exec( "cmd.exe /q /k start" );
Now, I know using rt.exec() is generally something people like to stray away from, however this isn't going to be a large-scale program, just a small text & object-based RPG in Java I'm making for fun with my friend. 现在,我知道人们通常会喜欢使用rt.exec(),但是这不会成为大型程序,只是我为Java设计的小型文本和基于对象的RPG。和我的朋友一起玩。
Right now, the command line is appearing properly but displays like I just normally opened the command line through cmd.exe. 现在,命令行显示正确,但是显示的方式就像我通常通过cmd.exe打开命令行一样。 Is there something I'm not understanding here?
这里有我不明白的东西吗?
With cmd.exe /q /k start
you end up with two cmd
prompts - the cmd.exe
one, and the start
one. 使用
cmd.exe /q /k start
您最终得到两个cmd
提示cmd.exe
一个,然后一个start
。 start
opens a new shell prompt, but not a quiet one (see here for more information about start
: https://technet.microsoft.com/en-us/library/cc770297(v=ws.11).aspx ). start
打开一个新的shell提示符,但没有一个安静的提示符(有关start
更多信息,请参见此处: https : //technet.microsoft.com/zh-cn/library/cc770297(v=ws.11 ) .aspx )。
I assume you only need that one cmd prompt, so try this instead: 我假设您只需要一个cmd提示符,因此请尝试以下操作:
Runtime.getRuntime().exec( "cmd.exe /q" );
Edit: 编辑:
I didn't account for that cmd.exe
terminates after being executed by Runtime.getRuntime().exec
. 我没有考虑到
cmd.exe
在被Runtime.getRuntime().exec
执行后终止。
After some trial and error, this should work: 经过一番尝试和错误后,这应该可以工作:
Runtime.getRuntime().exec( "cmd.exe /q /k start title /i" );
The /i
parameter to start
tells it to inherit the environment from where it was invoked, and this environment is quiet, thanks to the /q
parameter to cmd.exe
. 要
start
的/i
参数告诉它从调用它的位置继承环境,并且该环境安静,这要归功于cmd.exe
的/q
参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.