如何从sh写文件

2024-10-02 10:26:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个脚本,我喜欢通过子进程在python中执行(是的,它必须在sh中)。 现在我这样称呼sh

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

其中command是:

^{pr2}$

不幸的是,这让我:

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

有人能告诉我让命令在sh中工作的步骤,并解释原因。在


Tags: echoenv脚本进程varcheckshopen
2条回答

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

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

试试这个:

command = "echo 'someformat : : '${ENV_VAR}'/efc ;' > targetfile"
subprocess.check_call(["sh", "-c", command])

参数-c修改{}行为,以从下一个参数的字符串中读取命令。 参数必须包含在列表中。在

相关问题 更多 >

    热门问题