命名管道不会等到在 bash 中完成 [英] Named pipe does not wait until completion in bash

查看:21
本文介绍了命名管道不会等到在 bash 中完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的 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.jltest2.jl都写入output.txt 所以你必须在运行 test2.jltest2.jl 之前将文件移动到另一个目录, output.txttemp/ 目录,你必须在 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 中完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆