命名管道不会等到bash完成 [英] Named pipe does not wait until completion in bash
问题描述
在下面的test.jl中创建一个output.txt并生成一些控制台输出.控制台输出处理得很好.但是控制在回声之后立即返回,甚至在完全创建output.txt之前.在echo和mv之间放置等待会导致不确定的等待.回车应该在不杀死管道的情况下传递到管道吗?
In the following test.jl creates an output.txt and generates some console output. console output is very well handled. but control returns immediately after echo even before output.txt is created completely. placing a wait in between echo and mv causes an indefinite wait. Should a carriage return be passed to the pipe without killing the pipe yet?
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.jl
和test2.jl
都写入output.txt
,因此在运行test2.jl
或test2.jl
期望output.txt
在temp/
目录中,并且必须在text2.jl
运行之前将其移至该位置.
I understand that test.jl
and test2.jl
both write to output.txt
so you have to move the file to another directory before running test2.jl
or test2.jl
expects output.txt
in temp/
directory and you have to move it there before text2.jl
runs.
如果是,那么以下代码应该可以解决问题:
If yes then the following code should solve the problem:
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会运行mv
命令,并确保在test.jl
之后但在test2.jl
之前执行该命令.
In this way Julia runs mv
command and you make sure that it is executed after test.jl
but before test2.jl
.
但是实际上我们正要写一个名为例如script.jl
:
But actually we are getting to a point where it would be better to write a Julia script named e.g. script.jl
:
include("test.jl")
mv("output.txt", "temp/")
include("test2.jl")
并使用julia script.jl
运行它.
这篇关于命名管道不会等到bash完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!