-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomate.py
More file actions
25 lines (20 loc) · 759 Bytes
/
automate.py
File metadata and controls
25 lines (20 loc) · 759 Bytes
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
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import subprocess
import os
DEVNULL = open(os.devnull, 'w')
def execute(command):
output = subprocess.check_output(command, shell=True, stderr=DEVNULL)
if output:
return output.strip().split('\n')
"""
examples:
cmd_output_lines = execute("myCmd loco list")[2:] # execute a shell script and ignore the first two lines
for line in cmd_output_lines:
arg1, arg2 = line.split()[0:2] # extract only the columns we want :)
result = execute('otherCmd {}:{}'.format(arg1,arg2)) # execute some other command with these arguments
for result_line in result:
print(result_line)
"""