1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/library/command

40 lines
707 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
import traceback
2012-02-23 23:19:06 +01:00
args = sys.argv[1:]
startd = datetime.datetime.now()
try:
cmd = subprocess.Popen(args, shell=False,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = cmd.communicate()
except:
print json.dumps({
"failed" : 1,
"traceback" : traceback.format_exc()
})
sys.exit(1)
2012-02-23 23:19:06 +01:00
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)