public static void main(String[] args)
{
String cmd = "D:\\demo\\Test.bat";
try
{
Runtime.getRuntime().exec("cmd.exe /c "+cmd);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//运行结果是找不到: can not find the main class
//Test.bat是一个批处理文件,鼠标双击 bat 文件能运行应用程序
{
String cmd = "D:\\demo\\Test.bat";
try
{
Runtime.getRuntime().exec("cmd.exe /c "+cmd);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//运行结果是找不到: can not find the main class
//Test.bat是一个批处理文件,鼠标双击 bat 文件能运行应用程序
不是找不到Test.bat,而是找不到你的主方法。你把你全部代码贴上来看看。
import java.io.IOException;
import java.io.InputStreamReader;public class UseBarTest
{ /**
* @param args
*/
public static void main(String[] args)
{
String cmd = "D:\\demo\\Test.bat";
System.out.println("start******");
try
{
Runtime.getRuntime().exec("cmd.exe /c "+cmd);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("end*******");
}}
运行结果 是:
start******
end*******还有can not find the main class
你说的can not find the main class,是不是你在bat里加了java UseBarTest?
放在 "D:\\demo 目录下。
然后调用就好使。调用 test.bat 不好使:could not find the main class,program will exit;两者的差别是差别是test.bat 运行的是java程序。
//运行结果是找不到: can not find the main class
保存一下工程。
Runtime.getRuntime().exec("cmd.exe /c start Test.bat");