社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Ryan Thompson  »  全部回复
回复总数  1
10 年前
回复了 Ryan Thompson 创建的主题 » 使用sed命令的python[复制]

要回答最初的问题,要重定向输出,只需传递 stdout 论证 subprocess.call :

# Use a list of args instead of a string
input_files = ['file1', 'file2', 'file3']
my_cmd = ['cat'] + input_files
with open('myfile', "w") as outfile:
    subprocess.call(my_cmd, stdout=outfile)

但正如其他人指出的,外部命令的使用 cat 为了这个目的完全是无关的。