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

查看:20
本文介绍了命名管道不会等到 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.txt 期望 output.txtcode>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.

但实际上我们已经到了最好编写一个名为例如的 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天全站免登陆