-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_win_cmd.py
29 lines (23 loc) · 958 Bytes
/
run_win_cmd.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
import subprocess
# this function runs a windows command (cmd), printing the results
def run_win_cmd(cmd):
result = []
process = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# does this deal with empty results?
for line in process.stdout:
result.append(line)
errcode = process.returncode
if errcode is not None:
raise Exception('cmd %s, failed, see above for details', cmd)
return result
def run_win_cmd_no_result(cmd):
process = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
errcode = process.returncode
if errcode is not None:
raise Exception('cmd %s, failed, see above for details', cmd)