awk - gawk5 有没有办法并行启动 shell 命令?
问题描述
使用 gawk 5,我们可以启动 shell 命令,例如:
command = "echo toto"
command | getline
但是,这会挂起,直到命令完成,例如:
BEGIN {
command = "{ echo start >> test.log ; sleep 10 ; echo stop >> test.log ;}"
command | getline
print "terminated"
}
我尝试&
在命令末尾使用 a ,但没有成功:
BEGIN {
command = "{ echo start >> test.log ; sleep 10 ; echo stop >> test.log ;} &"
command | getline
print "terminated"
}
我希望能够将 shell 命令作为新进程启动并“忘记”它们。例如:
BEGIN {
command1 = "dosomething.sh &"
command1 | getline
command2 = "dosomething2.sh &"
command2 | getline
print "terminated"
}
这可以仅使用 gawk 5 来实现吗?
解决方案
| getline
等待阅读。所以输出一些东西以便它可以读取它。
$ awk 'BEGIN { cmd="{ echo something; ( echo start >&2 ; sleep 1; echo stop >&2 ) & }"; cmd | getline; print "Awk end"; }' <<<'' ; echo "Awk end"; sleep 2
Awk end
start
After awk
stop
推荐阅读
- node.js - EJS 模板没有加载两种方式的模板,如何解决这个问题?
- javascript - useState 未更新 useEffect 中的初始值
- excel - 使用动态命名范围的 Excel 过滤数据验证
- c# - 允许 gameObject 在不使用 Singleton 的情况下访问巨大的数据字典?
- arrays - 如何在 Matlab 中创建此代码的矢量化版本
- android - Android WebView 使用自定义 url 和 cookie 加载图像标签
- xml - 在 Scala 中读取带有属性名称的 XML
- java - 如何在 Apache Tomact 下接收专有协议?
- javascript - 如何在 RxDB 中的 pouchdb 实例上调用 bulkDocs 时同步修订
- mysql - 如何使用生成状态板的程序运行脚本?以及如何查阅为克雷塔罗州创建的印版?