Reputation: 3940
Can I pipe terminal input to a running Julia REPL?
In a terminal I might create a pipe
mkfifo juliapipe
Inside the Julia REPL I've tried
connect("juliapipe")
which returns the error
ERROR: connect: connection refused (ECONNREFUSED)
Is there a way to do this? Either with named pipes or any other way
Upvotes: 2
Views: 491
Reputation: 12051
Like @DanGetz suggested, one approach would be to display(eval(parse(f)))
until eof(f)
.
For instance, given a file test.jl
:
1 + 1
ans * 3
function f(x)
x ^ x
end
f(3)
println("Hello, World!")
we can in the REPL do
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!
which is not quite a REPL but somewhat similar to what you're looking for.
Upvotes: 2