ansible/library/command

31 lines
548 B
Text
Raw Normal View History

2012-02-23 23:19:06 +01:00
#!/usr/bin/python
try:
import json
except ImportError:
import simplejson as json
2012-02-23 23:19:06 +01:00
import subprocess
import sys
import datetime
args = sys.argv[1:]
startd = datetime.datetime.now()
cmd = subprocess.Popen(args, shell=False,
2012-02-23 23:19:06 +01:00
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)