Re: [問題] 如何利用程式叫出終端機?

看板Linux作者 (taco)時間15年前 (2009/04/24 09:39), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
可以參考一下(相關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
文章代碼(AID): #19yHXZ9k (Linux)
文章代碼(AID): #19yHXZ9k (Linux)