我正在尝试使用 Java 运行时运行以下命令:
find /home/Alison/workspace/FunctionalTestFramework/src/com/q1labs/qa/selenium/screens -type d | awk -F/ 'NF <= old_NF {print prev} {old_NF=NF; prev=$0} END {print $0}'
该命令在直接输入终端时工作正常,但在以下函数中运行时会出现以下错误:
find: paths must precede expression: |
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
Process exitValue: 1
Java函数:
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("find /home/Alison/workspace/FunctionalTestFramework/src/com/q1labs/qa/selenium/screens -type d | awk -F/ 'NF <= old_NF {print prev} {old_NF=NF; prev=$0} END {print $0}'");
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ( (line = br.readLine()) != null)
System.out.println(line);
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Throwable t)
{
t.printStackTrace();
}