Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
533 views
in Technique[技术] by (71.8m points)

redirect - Named pipe does not wait until completion in bash

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

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

In this way Julia runs mv command and you make sure that it is executed after test.jl but before test2.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")

and run it using julia script.jl.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...