Run shell command with “redirecting of an output from a subshell” statement within go

让人想犯罪 __ 提交于 2021-02-04 19:42:29

问题


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:


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")`)


来源:https://stackoverflow.com/questions/45698552/run-shell-command-with-redirecting-of-an-output-from-a-subshell-statement-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!