mirror of
https://github.com/kevinveenbirkenbach/splitted-secret.git
synced 2025-09-09 19:57:17 +02:00
Refactored code
This commit is contained in:
30
scripts/classes/Cli.py
Normal file
30
scripts/classes/Cli.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# This class offers easy logik to execute cli commands
|
||||
# @author Kevin Veen-Birkenbach [kevin@veen.world]
|
||||
|
||||
import subprocess
|
||||
|
||||
class Cli:
|
||||
|
||||
def __init__(self):
|
||||
self.command = '';
|
||||
self.output = [];
|
||||
pass
|
||||
|
||||
def executeCommand(self,command):
|
||||
self.command = command
|
||||
process = subprocess.Popen([command], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||
out, err = process.communicate()
|
||||
stdout = out.splitlines()
|
||||
self.output = []
|
||||
for line in stdout:
|
||||
self.output.append(line.decode("utf-8"))
|
||||
if process.wait() > bool(0):
|
||||
print(command, out, err)
|
||||
raise Exception("Exitcode is greater then 0")
|
||||
return self.output
|
||||
|
||||
def getOutputString(self):
|
||||
return str(' '.join(self.output))
|
||||
|
||||
def getCommandString(self):
|
||||
return self.command
|
Reference in New Issue
Block a user