gpt4 book ai didi

python - 如何从sh写入文件

转载 作者:太空宇宙 更新时间:2023-11-04 08:14:51 25 4
gpt4 key购买 nike

我有一个脚本,我喜欢通过 subprocesspython 中执行(是的,它必须在 sh 中)。现在我这样调用 sh:

subprocess.check_call( ['sh' + command] )

command 是:

echo 'someformat : : '${ENV_VAR}'/efc ;' > targetfile

可悲的是,这给了我:

sh: 0: Can't open echo 'someformat : : '${ENV_VAR}'/efc ;' > targetfile

有人可以指导我完成使命令在 sh 中运行的步骤并解释原因吗。

最佳答案

您必须使用 -c 参数运行 sh:

subprocess.check_call( ['sh', '-c', command] )

关于python - 如何从sh写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16230603/

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