命名管道不会等到 bash 完成

Named pipe does not wait until completion in bash

在下面 test.jl 创建一个 output.txt 并生成一些控制台输出。控制台输出处理得很好。但是在 echo 之后甚至在完全创建 output.txt 之前立即控制 returns。在 echo 和 mv 之间放置等待会导致无限期等待。是否应该在不关闭管道的情况下将马车 return 传递到管道?

mkfifo pipe
sleep 1000000 > pipe &
julia <pipe >stdout.txt 2>stderr.txt &

echo "include(\"test.jl\")" > pipe
mv output.txt temp/
echo "include(\"test2.jl\")" > pipe

谢谢!

我知道 test.jltest2.jl 都写入 output.txt 所以你必须在 运行ning test2.jl 之前将文件移动到另一个目录或者test2.jl 期望 output.txttemp/ 目录中,您必须在 text2.jl 运行 之前将其移动到那里。

如果是,那么下面的代码应该可以解决问题:

mkfifo pipe
sleep 1000000 > pipe &
julia <pipe >stdout.txt 2>stderr.txt &

echo "include(\"test.jl\")" > pipe
echo "mv(\"output.txt\", \"temp/\")" > pipe
echo "include(\"test2.jl\")" > pipe

以这种方式 Julia 运行s mv 命令,你确保它在 test.jl 之后但在 test2.jl.

之前执行

但实际上我们已经到了这样的地步,最好编写一个 Julia 脚本,例如script.jl:

include("test.jl")
mv("output.txt", "temp/")
include("test2.jl")

和运行它使用julia script.jl