-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommand.py
More file actions
34 lines (23 loc) · 673 Bytes
/
Copy pathcommand.py
File metadata and controls
34 lines (23 loc) · 673 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
26
27
28
29
30
31
32
33
34
from re import MULTILINE, findall
from subprocess import run
def commander(command: str) -> tuple[str, int]:
"""Execute command on bash"""
outcode = run(
command,
shell=True,
capture_output=True,
)
returnCode = outcode.returncode
if returnCode == 0:
output = outcode.stdout.decode()
return output, returnCode
error = outcode.stderr.decode()
return error, returnCode
command = input("Enter Command:")
pattern = input("Enter Pattern\n")
output, rcode = commander(command)
if rcode == 0:
for match in findall(pattern, output, MULTILINE):
print(match)
else:
print("Error:", output)