gawk5 有没有办法并行启动 shell 命令?

Is there a way with gawk5 to launch shell commands in parallel?

使用 gawk 5,我们可以启动 shell 命令,例如:

command = "echo toto"
command | getline

但是,这会挂起直到命令完成,例如:

BEGIN {
    command = "{ echo start >> test.log ; sleep 10 ; echo stop >> test.log ;}"
    command | getline
    print "terminated"
}

我尝试在命令末尾使用 &,但没有成功:

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