作者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
→ ogamenewbie:sh... 你那個 helloworld 是可以用 sh 的嗎 10/30 15:21
→ ogamenewbie:且你執行完了以後, 有用什麼把 Runtime 接回來顯示嘛 10/30 15:23
→ ogamenewbie:當然也可能是我對 Runtime 理解錯誤啦... 平常不太用 10/30 15:23