Re: [問題] 如何利用程式叫出終端機?
可以參考一下(相關package請自行import):
private static List<String> Exec (final String args) {
String cmd = args;
Runtime run = Runtime.getRuntime();
String line = null;
List<String> cmdOut = new ArrayList<String>();
try {
Process pr = run.exec(cmd);
BufferedReader buf =
new BufferedReader(new InputStreamReader(pr.getInputStream()));
while ((line = buf.readLine()) != null) {
cmdOut.add(line);
}
pr.waitFor();
return cmdOut;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
※ 引述《csdunhill (MR.阿花)》之銘言:
: 因為最近在弄一個case,case裡一些地方需要能夠自動執行,
: 所以想問說java裡要如何能自動啟動linux下的終端機?
: 另外有辦法利用java程式下執終端機裡的command嗎?
: 謝摟~
--
=====================================
| James aka. taco -- |
| War doesn't determine who's right,|
| just who's left. |
| Same to LIFE...?! |
=====================================
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.137.41.11
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):