您可以使用stdout=
和stderr=
参数来subprocess.call()
定向stdout
或定向stderr
到您选择的文件描述符。所以也许是这样的:
import os
devnull = open(os.devnull, 'w')
subprocess.call(shlex.split(
'/usr/local/itms/bin/iTMSTransporter -m lookupMetadata '
'-apple_id %s -destination %s' % (self,apple_id, self.destination)),
stdout=devnull, stderr=devnull)
subprocess.PIPE
如果不从管道读取数据,则使用,可能会导致程序在生成大量输出时阻塞。
正如@yanlend在评论中提到的那样,Python的更新版本(3.x)包括subprocess.DEVNULL
以更方便和可移植的方式解决此问题。在这种情况下,代码如下所示:
subprocess.call(shlex.split(
'/usr/local/itms/bin/iTMSTransporter -m lookupMetadata '
'-apple_id %s -destination %s' % (self,apple_id, self.destination)),
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)