ansible/library/command
Jeremy Katz ef8ea13495 Fall back to standalone simplejson module
CentOS5 has python 2.4 which doesn't have a built-in json
module
2012-02-23 20:52:53 -05:00

31 lines
547 B
Python
Executable file

#!/usr/bin/python
try:
import json
except ImportError:
import simplejson as json
import subprocess
import sys
import datetime
args = sys.argv[1:]
startd = datetime.datetime.now()
cmd = subprocess.Popen(args, shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
endd = datetime.datetime.now()
delta = endd - startd
result = {
"stdout" : out,
"stderr" : err,
"rc" : cmd.returncode,
"start" : str(startd),
"end" : str(endd),
"delta" : str(delta),
}
print json.dumps(result)