gpt4 book ai didi

bash - 在 go 中使用 "redirecting of an output from a subshell"语句运行 shell 命令

转载 作者:IT王子 更新时间:2023-10-29 01:41:22 26 4
gpt4 key购买 nike

根据 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,这意味着您实际上需要调用 bash 使用 bash:

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

关于bash - 在 go 中使用 "redirecting of an output from a subshell"语句运行 shell 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45698552/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com