gpt4 book ai didi

python - 在 python 中而不是在 shell 中使用 os.system 时出错

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:24:23 25 4
gpt4 key购买 nike

<分区>

我正在尝试重定向 gnu make 的输出。想要将 ALL 重定向到 STDOUT 和 all.log,并且仅将错误重定向到 error.log。

下面是我的程序

#!/usr/bin/env python
import optparse
import os
import sys
import commands

command = 'make all > >(tee -a all.log ) 2>&1 2> >(tee -a error.log )'
SysReturnVal=os.system(command)

print "system return value is ", SysReturnVal

当我执行它时

sh: -c: line 0: syntax error near unexpected token `>'
sh: -c: line 0: `make all > >(tee -a all.log ) 2>&1 2> >(tee -a error.log )'

但是在 linux bash shell 上执行相同的命令却没有错误。

make all > >(tee -a  all.log ) 2>&1 2> >(tee -a  error.log )

为什么在使用 os.system 的 python 脚本中运行时失败,但在终端/bash shell 中却没有?

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