我可以通过管道将终端输入传输到正在运行的 Julia REPL 吗?
在终端中我可能会创建一个管道
mkfifo juliapipe
在 Julia REPL 中我尝试过
connect("juliapipe")
返回错误
ERROR: connect: connection refused (ECONNREFUSED)
有办法做到这一点吗?使用命名管道或任何其他方式
最佳答案
就像 @DanGetz 建议的那样,一种方法是 display(eval(parse(f)))
直到 eof(f)
。
例如,给定一个文件 test.jl
:
1 + 1
ans * 3
function f(x)
x ^ x
end
f(3)
println("Hello, World!")
我们可以在REPL中做
julia> open("test.jl") do f
global ans
while !eof(f)
cmd = parse(f)
println("file> $cmd")
ans = eval(cmd)
if ans !== nothing
display(ans)
println()
end
end
end
file> 1 + 1
2
file> ans * 3
6
file> function f(x) # none, line 3:
x ^ x
end
f (generic function with 1 method)
file> f(3)
27
file> println("Hello, World!")
Hello, World!
这不完全是 REPL,但与您正在寻找的内容有些相似。
关于pipe - Julia - 管道到 Julia REPL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39489021/