问题描述
在下面的 test.jl 中创建一个 output.txt 并生成一些控制台输出.控制台输出处理得很好.但是在完全创建 output.txt 之前,控制权会在 echo 之后立即返回.在 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
.
但实际上我们已经到了编写一个名为 e.g. 的 Julia 脚本会更好的地步.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 中完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!