把「iwconfig的」 shell腳本里面,你可以從機器人,加工標準輸出,直到對其做運行過程中直接..這樣品執行殼名= /斌/ pars_submit。
public String getFfmpeg(@QueryParam("infil1") String infil1,
@QueryParam("infil2") String infil2, @QueryParam("otfil") String otfil,
@QueryParam("t") String time) {
String outfil = "dummy.mp4";
List<String> command = new ArrayList<String>();
command.add("vendor/bin/pars_submit");
command.add(infil1);
command.add(infil2);
command.add(otfil);
command.add(time);
System.out.println("Starting process " +command.toString());
ProcessBuilder builder = new ProcessBuilder(command);
Map<String, String> environ = builder.environment();
// for(Entry<String, String> entry : environ.entrySet()){
// System.out.println("ENV " +entry.getKey() + " " +entry.getValue());
// }
// builder.redirectErrorStream(true);
Process process = null;
try {
process = builder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
//System.out.println(line);
outfil=line;
}
// int exitVal = process.waitFor();
// System.out.println("Process exitValue: " + exitVal);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally {
if (process != null) {
process.destroy();
process = null;
}
}
return outfil;
}
你試過了嗎? – Cairnarvon 2013-03-03 22:12:02
是在上一個鏈接顯示我的工作,但沒有價值返回 – Hana90 2013-03-03 22:13:44
在C/C++中這樣做的好處在哪裏。我認爲Java本身對執行shell命令有相當不錯的支持? – 2013-03-03 23:55:43