私信  •  关注

Alexander Stohr

Alexander Stohr 最近回复了

在深入研究之后,我发现了一个与平台无关、支持错误通道(stderr)和执行故障的解决方案,它甚至可以避免操作系统特定的组件,如bash/cmd.exe:

try {
  def command = ['python', '-c', /print("this is a sample text.")/];
  if (System.properties['os.name'].toLowerCase().contains('windows'))
  {
    command[2] = command[2].replaceAll(/\"/, /\\\"/)
  }
  println "command=" + command
  def proc = command.execute()
  def rc = proc.waitFor()
  println "rc=" + rc

  def err = proc.err.text
  if( err != "" ) { print "stderr=" + err }

  def out = proc.text
  if( out != "" ) { print "stdout=" + out }
} catch(Exception e) {
  println "exception=" + e
}
println ""