mirror of
https://github.com/ItsDrike/dotfiles.git
synced 2024-12-26 05:04:34 +00:00
Add command execution using subprocess
This commit is contained in:
parent
9d1012656d
commit
7872a839d8
27
src/util/command.py
Normal file
27
src/util/command.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import subprocess
|
||||
|
||||
|
||||
def execute(command) -> None:
|
||||
"""Execute bash `command`, return the returncode (int)"""
|
||||
command = command.split(' ')
|
||||
subprocess.call(command)
|
||||
|
||||
|
||||
def get_output(command) -> str:
|
||||
"""Get standard output of `command`"""
|
||||
command = command.split(' ')
|
||||
return subprocess.run(
|
||||
command,
|
||||
stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE
|
||||
).stdout.decode('utf-8')
|
||||
|
||||
|
||||
def get_return_code(command) -> int:
|
||||
"""get return code of `command` (int)"""
|
||||
command = command.split(' ')
|
||||
return subprocess.run(
|
||||
command,
|
||||
stderr=subprocess.STDOUT,
|
||||
stdout=subprocess.PIPE
|
||||
).returncode
|
Loading…
Reference in a new issue