I want to write the output of a shell command in a file using python. When I'm trying to do this the command is being run in the shell itself and outputting to the shell itself. Can I suppress the output of call
and write it to a file?
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)
I tried subprocess
and os
methods but they didn't work. Still I am seeing command output in shell and nothing is being written the file ? Can you tell what am I missing ?