各位好,小弟很少写JAVA程序,我在网上参考了打开记事本的代码,改成了自己的,代码如下,但找不到如何关闭这个进程的代码,请教各位,,谢谢各位
Runtime rt = Runtime.getRuntime();
String command = "D:\\Debug\\test.exe";
try
{
rt.exec(command);
}
catch (IOException e)
{
e.printStackTrace();
}
Runtime rt = Runtime.getRuntime();
String command = "D:\\Debug\\test.exe";
try
{
rt.exec(command);
}
catch (IOException e)
{
e.printStackTrace();
}
Process p = null;
String command = "D:\\Debug\\test.exe";
try
{
p = rt.exec(command);
}
catch (IOException e)
{
e.printStackTrace();
}
if(p!=null)
{
p.destroy();
}
rt.exec("cmd /c taskkill /IM D:\\Debug\\test.exe /F");
就可以结束掉D:\\Debug\\test.exe这个程序了
其具体参数设置可以 cmd--》TASKKILL /?来获得帮助提示
import java.io.IOException;
public class Test {
public static void main(String[] args) {
Runtime rt = Runtime.getRuntime();
//JAVA Runtime.exec()执行多个参数的命令方法,如果参数包含空格,则需要提供一个数组来提供参数
//并且注意,比如cd dir这种命令,即使以数组形式提供也无法正确执行,因为在xp系统中,只有cmd命令
//cd 命令不是当前环境所能解释的
String[] command1=new String[]{"cmd","cd","D:\\Debug"};
String command = "taskkill /F /IM test.exe";
try
{
rt.exec(command1);//返回一个进程
rt.exec(command);
System.out.println("success closed");
}
catch (IOException e)
{
e.printStackTrace();
}
}}
针对,你这题我写了个例子,应可以直接运行,没问题