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

30 lines
548 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=False,
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)