从Java代码中运行程序 [英] Running a program from within Java code
本文介绍了从Java代码中运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用一段Java代码调用程序的最简单方法是什么? (我想运行的程序是aiSee,它可以从命令行或从Windows GUI运行;我在Vista上,但代码也将在Linux系统上运行。)
What is the simplest way to call a program from with a piece of Java code? (The program I want to run is aiSee and it can be run from command line or from Windows GUI; and I am on Vista but the code will also be run on Linux systems).
推荐答案
Take a look at Process and Runtime classes. Keep in mind that what you are trying to accomplish is probably not platform independent.
以下是一段可能有用的代码:
Here is a little piece of code that might be helpful:
public class YourClass
{
public static void main(String args[])
throws Exception
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("name_of_your_application.exe");
int exitVal = proc.exitValue();
System.out.println("Process exitValue: " + exitVal);
}
}
One question in S.O. discussing similiar issues. Another one. And another one.
这篇关于从Java代码中运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文