gpt4 book ai didi

java - 执行 Runtime.getRuntime().exec AWK 时出现问题

转载 作者:行者123 更新时间:2023-12-02 05:47:28 24 4
gpt4 key购买 nike

我想执行以下命令:

 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.

最佳答案

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

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

关于java - 执行 Runtime.getRuntime().exec AWK 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23915478/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com