如何利用程式叫出終端機? - Linux

Table of Contents

可以參考一下(相關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...?! |
=====================================

--

All Comments