作者CSLabor (电脑工人)
看板java
标题[问题] 在Linux底下执行外部程式?
时间Sat Oct 30 14:57:51 2010
我在Linux底下已经写了一个简单的helloworld执行档
档名叫helloworld
用途是print出一串helloworld
现在我要用java程式呼叫这个执行档
这个Java程式档名叫做helloworld.java
helloworld.java内容如下
import java.io.*;
public class helloworld{
public static void main(String[] args){
try{
String[] command={"/bin/sh","./helloworld"};
Runtime.getRuntime().exec(command);
}
catch(IOException e){
e.printStackTrace();
}
}
}
我的程式编译执行後没有反应
可以请有经验的大大可以帮我看一下吗?
在这边先谢谢有经验的前辈
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.116.177.31
※ CSLabor:转录至看板 Linux 10/30 14:59
1F:→ ogamenewbie:sh... 你那个 helloworld 是可以用 sh 的吗 10/30 15:21
2F:→ ogamenewbie:且你执行完了以後, 有用什麽把 Runtime 接回来显示嘛 10/30 15:23
3F:→ ogamenewbie:当然也可能是我对 Runtime 理解错误啦... 平常不太用 10/30 15:23