如何在包的build.jl中使用`sudo`

时间:2016-02-15 08:50:42

标签: julia

build.jl

run(`sudo -S mkdir test`)

当您运行Pkg.build("TestBuild")时,您将无法输入密码。

julia> Pkg.build("TestBuild")
INFO: Building TestBuild
[sudo] password for guo: 
==============================[ ERROR: TestBuild      ]==============================

LoadError: failed process: Process(`sudo -S mkdir test`, ProcessExited(1))    

此演示程序包TestBuild位于Github

如何在build.jl中使用sudo

1 个答案:

答案 0 :(得分:1)

run(`mkfifo /tmp/pwd-fifo`)
prompt = "sudo need your password, please run [read -s p && echo \$p > /tmp/pwd-fifo] in another shell.\n\
"
sudo = @async run(`bash -c "sudo -S -p '' touch /tmp/tx < /tmp/pwd-fifo"`)
print(prompt)
wait(sudo)

以上代码由KDr2

提供