2016-03-18 52 views
0

這裏是我的代碼:錯誤:不支持SysV的選項時使用Groovy .execute()

"ps -o pid -o cmd -e|grep -E 'cmake /home/roroco/.clion'".execute(),我得到error: unsupported SysV option,但是當我嘗試在終端這個CMD,它的工作,如何解決它,我所看到的ask ubuntu question,它不工作,我只有一個/斌/ PS

+0

這是什麼'命令-v ps'在運行時在終端上說?你從groovy得到什麼? –

+0

@EtanReisner它顯示'/ bin/ps' – asullaherc

回答

0

我前面加上["/bin/sh", "-c"解決這個問題,之前常規.execute(),這裏是我的代碼:

static String sh(String... args) { 
    String cmd = args.join(" ") 
    Out.out "run cmd: ${cmd}", "ro.Out.out(Out.groovy)" 
    StringBuffer out = new StringBuffer() 
    StringBuffer err = new StringBuffer() 
    Process p = ["/bin/sh", "-c", cmd].execute() 
    p.consumeProcessOutput(out, err) 
    int status = p.waitFor(); 
    if (status != 0) { 
     String msg = err.toString() 
     if (msg == "") { 
      msg = out.toString() 
     } 

     throw new Sh.Err("cmd: ${cmd}\n\nstderr: ${msg}") 
    } else { 
     out.toString() 
    } 
} 
相關問題