-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.py
28 lines (24 loc) · 760 Bytes
/
command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""{
"module": "command",
"handler": "run",
"jobparam": {"cmd" : {"L": ["ls", "-1"]}}
}
"""
import subprocess
import logging
logging.config.fileConfig('etc/worker_logging.conf')
def simple_run(jobid, jobparam):
"""just execute the command"""
command = []
if "S" in jobparam["cmd"]:
command = jobparam["cmd"]["S"].split(" ")
elif "L" in jobparam["cmd"]:
command = jobparam["cmd"]["L"]
logging.info(command)
p = subprocess.Popen(command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
logging.info("stdout: %s", stdout)
logging.info("stderr: %s", stderr)