亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 java 運行 AWK shell 腳本時沒有響應

使用 java 運行 AWK shell 腳本時沒有響應

慕容3067478 2021-09-12 14:37:03
我正在嘗試使用 java 中的 awk。我寫了下面的代碼,但沒有輸出。public class ShellScriptExecution {    public static void main (String[] a) {        ShellScriptExecution shellsc = new ShellScriptExecution();        String command = "awk '/Ayushi/ {print}' /home/ayushi/Desktop/testAwk.txt ";        String op = shellsc.execute(command, a);        System.out.println(op);    }    private String execute(String command, String[] a) {        StringBuffer sb = new StringBuffer();        Process p;        try {            //            //            p = Runtime.getRuntime().exec(command);            p.waitFor();            BufferedReader reader =                     new BufferedReader(new InputStreamReader(p.getInputStream()));                String line = "";                       while ((line = reader.readLine())!= null) {                sb.append(line + "\n");            }        } catch (IOException | InterruptedException e) {            e.printStackTrace();        }        return sb.toString();    }}請提供一些有關如何在java中使用awk的幫助?如果有其他方法可以做到嗎?
查看完整描述

3 回答

?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

只是一個建議,因為由于聲譽點不足,我仍然無法發表評論。你為什么不創建一個本地 shell 腳本并在awk那里執行你的命令并使用 java 來觸發所說的 shell 腳本?我覺得這樣更方便。在這個問題中,您想awk在 java 中使用,但實際上它是一個可以在 shell 腳本中使用的“命令行實用程序”。如果您真的想awk在 java 中使用,那么可以嘗試搜索第三方庫。


查看完整回答
反對 回復 2021-09-12
  • 3 回答
  • 0 關注
  • 327 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號