【问题标题】:Run shell command with "redirecting of an output from a subshell" statement within go在 go 中使用“重定向子 shell 的输出”语句运行 shell 命令
【发布时间】:2017-08-15 17:49:16
【问题描述】:

根据run bash command in new shell and stay in new shell after this command executes,我该如何运行命令:

bash --rcfile <(echo "export PS1='> ' && ls")

在 golang 中?我已经尝试了许多exec.Command() 的组合,但它们没有用。例如:

exec.Command("bash", "--rcfile", `<("echo 'ls'")`)

我也读过这个os, os/exec: using redirection symbol '<' '>' failed,但我想我的情况可能有点复杂。

【问题讨论】:

    标签: bash go command-line


    【解决方案1】:

    你快到了 - 我认为你正在使用管道 调用 bash,这意味着你实际上需要调用 bash 使用 bash:: p>

    exec.Command("bash", "-c", `bash --rcfile <(echo "export PS1='> ' && ls")`)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 2014-06-26
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多