pipe - Julia - 管道到 Julia REPL

标签 pipe julia named-pipes read-eval-print-loop

我可以通过管道将终端输入传输到正在运行的 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/

相关文章:

dataframe - 如何改变 DataFrame?

Java MySQL - 命名管道连接在关闭时抛出警告

bash - 为什么 "yes | sleep 10"管道不会失败

linux - 为什么 `ls hello.txt | cat` 与 `cat hello.txt` 不同?

julia - 如何在 Julia 中将向量(列表)广播到元组中?

types - Julia 设计 : Silently Defining/Naming Types in Macros

c# - 命名管道示例

c - 我的第一个 Windows 命名管道,不知道出了什么问题

c - fgetc 在轮询管道后仍然阻塞

c - 基本 shell 实现中的管道