使用Java启动Windows exe [英] Use Java to start a Windows exe
问题描述
我想了解如何使用Java代码在Windows中打开任何exe.我之前曾经搜索过Google,但我认为它们只是向我展示了他们使用的部分代码,因为它似乎没有编译.
I want to find out how to open any exe in Windows using Java code. I have searched Google before and they only show me part of the code that they use, I think, because it doesn't seem to compile.
我已经下载了JDK 7进行编译.我目前不使用Eclipse,而且解释一下我需要做些什么才能使其更详细地工作会很有帮助.
I have downloaded JDK 7 to compile. I don't use Eclipse at the moment and also explaining what I had to do to get it to work in detail would help a lot.
Sri Harsha Chilakapati说的话:我需要为代码创建一个类吗?
to what Sri Harsha Chilakapati said: would i need to create a class for the code?
感谢那些回答,但我没有完全理解您的意思,但是我确实找到了一个拥有我所追求的网站: http://www.rgagnon.com/javadetails/java-0014.html
Thanks to those who answered but i didn't quite get what you meant but i did however manage to find a website which had what i was after: http://www.rgagnon.com/javadetails/java-0014.html
public class Test {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec(
"\"c:/program files/windows/notepad.exe\"");
p.waitFor();
}
}
以上就是我所追求的,但是无论如何,再次感谢那些回答的人.
the above was what i was after but thanks again anyway to the people who answered.
推荐答案
尝试一下.
String myExe = "C:\\MyExe.exe";
String args = "";
Runtime.getRuntime().exec(myExe + " " + args);
希望这会有所帮助.
这篇关于使用Java启动Windows exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!