forked from rock-simulation/pybob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute.py
40 lines (35 loc) · 1.04 KB
/
execute.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
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/env python
import os
import errno
import colorconsole as c
import subprocess
def makeDir(path):
try:
os.makedirs(path)
except OSError as exc:
pass
def simpleExecute(cmd):
p = subprocess.Popen(" ".join(cmd), stderr=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
p.communicate()
def do(cmd, cfg=None, errorString=None, path=None, logFile=None):
outpipe = subprocess.PIPE
if cfg and logFile:
logPath = cfg["devDir"] + "/autoproj/bob/logs"
if not os.path.isdir(logPath):
makeDir(logPath)
outpipe = open(logPath+"/"+logFile, "w")
p = subprocess.Popen(" ".join(cmd), stdout=outpipe, stderr=outpipe,
cwd=path, shell=True)
if cfg and logFile:
outpipe.close()
out = ""
err = ""
if cfg and logFile:
p.wait()
else:
out, err = p.communicate()
if len(err) > 0:
if cfg and errorString > 0:
c.printError(err)
cfg["errors"].append(errorString)
return out,err,p.returncode