2016-03-18 22 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() 
    } 
} 
相关问题