donglang6656 2017-08-15 17:49
浏览 143
已采纳

在go中运行带有“从子shell重定向输出”语句的shell命令

According to run bash command in new shell and stay in new shell after this command executes, how can I run command:

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

within golang? I've tried many combinations of exec.Command() but they did't work. For example:

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

I've also read this os, os/exec: using redirection symbol '<' '>' failed, but I think maybe my case is a bit more complicated.

  • 写回答

1条回答 默认 最新

  • dongying195959 2017-08-15 17:53
    关注

    You're almost there - I think the confusion is you're using piping to call bash, which means you actually need to call bash using bash:

    exec.Command("bash", "-c", `bash --rcfile <(echo "export PS1='> ' && ls")`)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面