如何在后台运行从Java代码的命令行? [英] How do I run command line from Java code in the background?

查看:689
本文介绍了如何在后台运行从Java代码的命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下行运行批处理文件

I have the following line to run a batch file,

Process process = Runtime.getRuntime().exec("cmd /c start rake.bat");

但是我想让它在后台运行,而不是向用户显示命令行。如何更改它以执行此操作?

But I want it to run in the background and not display the command line to the user. How can I change it to do this?

问题是命令窗口打开并中断程序GUI。

The problem is that the command window opens and intrupts the programs GUI. I just want the command window to not be visible while it is executing the batch file.

推荐答案

完全删除开始将会使命令窗口在执行批处理文件时不可见。做你想要的(因为这是创建窗口):

Removing the 'start' completely will do what you want (as this is what is creating the window):

Process process = Runtime.getRuntime().exec("cmd /c rake.bat");

我测试了这个,它的工作原理,如果你想与命令提示符必须有输入和输出流,也不会忘记你的错误流
正如在注释中所说,虽然删除开始在XP不帮助(因为它不工作)。

I have tested this and it works, ofcourse if you want to communicate with the command prompt you'd have to have Input and Output streams, also not forgetting your Error stream As stated in the comment though removing 'start' on XP wont help (as it wont work).

这篇关于如何在后台运行从Java代码的命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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