存储shell命令产生的文本行

2024-10-02 18:24:52 发布

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

以下是与本节代码相关的代码:

command1 = '/usr/local/GMT5SAR/bin/ALOS_baseline ' + str(master_file) + ' ' + str(master_file)
print command1
p1 = Popen(command1, shell=True, stdout=PIPE)
out,err = p1.communicate()
print out

我的命令运行正常。这是我的主机截图

enter image description here

我需要存储表示lon_tie_point .....lat_tie_point .....的行。我遇到的问题是这些行没有包含在out中,这就是我要打印的内容。我该怎么做呢


Tags: 代码masterbinusrlocaloutfilepoint
1条回答
网友
1楼 · 发布于 2024-10-02 18:24:52

似乎包含所需信息的行正在stderr而不是stdout上打印。从^{} documentation

subprocess.STDOUT

Special value that can be used as the stderr argument to Popen and indicates that standard error should go into the same handle as standard output.

基于此,我认为以下方法可能有效:

command1 = '/usr/local/GMT5SAR/bin/ALOS_baseline ' + str(master_file) + ' ' + str(master_file)
print command1
p1 = Popen(command1, shell=True, stdout=PIPE, stderr=STDOUT)
out,err = p1.communicate()
print out

相关问题 更多 >