我想使用python在shell文件中编写shell命令的输出。当我尝试这样做时,命令正在shell本身运行并输出到shell本身。我可以抑制call
的输出并将其写入文件吗?
from subprocess import call
import time
class PtsOutput(object):
def __init__(self, camera, video_filename, pts_filename, pi_time_filename):
self.camera = camera
self.video_output = io.open(video_filename, 'wb')
self.pi_time_output = io.open(pi_time_filename, 'w')
self.start_time = None
def write(self, buf):
self.video_output.write(buf)
if self.camera.frame.complete and self.camera.frame.timestamp:
if self.start_time is None:
self.start_time = self.camera.frame.timestamp
**starttime = call(["date","+%s%N"])**
self.pi_time_output.write('# frame start time: %s\n'%starttime)
我尝试了subprocess
and os
方法,但它们没有用。我仍然看到shell中的命令输出,没有写入文件?你能说出我错过了什么吗?