错误:使用groovy .execute()时不支持的SysV选项

时间:2016-03-18 03:29:25

标签: groovy

这是我的代码:

"ps -o pid -o cmd -e|grep -E 'cmake /home/roroco/.clion'".execute()我获得error: unsupported SysV option,但是当我在终端上尝试此cmd时,它可以正常工作,如何修复它,我看到ask ubuntu question,它不起作用,我只有一个/ bin / ps

1 个答案:

答案 0 :(得分:0)

我使用pre ["/bin/sh", "-c"修复它,然后在groovy .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()
    }
}