medit/getoutput.py

20 lines
580 B
Python
Raw Normal View History

2015-07-19 13:56:03 -07:00
import subprocess
import sys
import os
#print "Output file:", sys.argv[1]
#print "Working dir:", os.getcwd()
#print "Executing command:", sys.argv[2:]
output = subprocess.check_output(sys.argv[2:], stdin=None, shell=False, universal_newlines=False)
output = output.replace('\r\n', '\n').replace('\r', '\n')
filename = sys.argv[1]
tmp = filename + '.tmp'
2016-10-03 00:15:41 -07:00
if not os.path.exists(os.path.dirname(tmp)):
os.makedirs(os.path.dirname(tmp))
2015-07-19 13:56:03 -07:00
with open(tmp, 'w') as f:
f.write(output)
if os.path.exists(filename):
os.remove(filename)
os.rename(tmp, filename)