我想在julia中捕获shell命令的结果
在ipython这工作:
[1]: x = ! date
In [2]: x
Out[2]: ['Thu Dec 14 15:34:06 PST 2017']
Run Code Online (Sandbox Code Playgroud)
我已经试过了
julia> x = ;date
ERROR: syntax: unexpected ;
julia> x = readstring(`date`)
"Thu Dec 14 21:33:48 PST 2017\n"
julia> x
"Thu Dec 14 21:33:48 PST 2017\n"
Run Code Online (Sandbox Code Playgroud)
readtring是实现这个目标的最佳方式吗?还是有一个; 方式呢?
按下;仅适用于Julia REPL将其移动到> shell模式,并且仅当您位于行的开头时才有效.
在程序中;是表达式终止符.因此x = ;date是一个错误,因为x =表面格式不正确.
从朱莉娅0.7开始,你将无法使用readstring而是
read(`date`, String)
Run Code Online (Sandbox Code Playgroud)
如果你不想要一个字符串而只需要一个原始字节数组就可以写
read(`date`)
Run Code Online (Sandbox Code Playgroud)