发出执行Runtime.getRuntime()。exec AWK

时间:2014-05-28 15:12:16

标签: java unix awk

我想执行以下命令:

 awk '{print "1" $0}' /path_toFile/file.txt

这是我的代码:

String[] params = new String[3];
params[0] = "/usr/bin/awk";
params[1] = "print \"1\" $0";
params[2] = "/path_toFile/file.txt";

Runtime.getRuntime().exec(params);

获取错误:

Exit Value = 2
 syntax error The source line is 1.
 The error context is
                 >>> print <<<  \"1\" $0
 awk: Quitting
 The source line is 1.

1 个答案:

答案 0 :(得分:2)

围绕大括号({..})缺少代码:

params[1] = "{print \"1\" $0}";