You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/library/command

46 lines
839 B
Plaintext

#!/usr/bin/python
try:
import json
except ImportError:
import simplejson as json
import subprocess
import sys
import datetime
import traceback
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 (OSError, IOError), e:
print json.dumps({
"failed": 1,
"error": str(e),
})
sys.exit(1)
except:
print json.dumps({
"failed" : 1,
"traceback" : traceback.format_exc()
})
sys.exit(1)
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)