2023-10-10 20:11:57 +00:00
|
|
|
import subprocess
|
|
|
|
|
2024-02-16 20:31:38 +00:00
|
|
|
import txt
|
2023-10-10 20:11:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_tuples_args(tuples) -> list[str]:
|
|
|
|
args = []
|
|
|
|
for item in tuples:
|
|
|
|
if type(item) is tuple:
|
|
|
|
args.extend(item)
|
|
|
|
else:
|
|
|
|
args.append(item)
|
|
|
|
return args
|
|
|
|
|
|
|
|
|
|
|
|
def run(*tuples) -> subprocess.CompletedProcess:
|
|
|
|
return subprocess.run(get_tuples_args(tuples), capture_output=False)
|
|
|
|
|
|
|
|
|
2024-02-16 20:42:48 +00:00
|
|
|
def run_line(*tuples, charset: str = txt.CHARSET) -> str:
|
2023-10-10 20:11:57 +00:00
|
|
|
lines = run_lines(*get_tuples_args(tuples), charset=charset)
|
|
|
|
return lines[0]
|
|
|
|
|
|
|
|
|
2024-02-16 20:42:48 +00:00
|
|
|
def run_lines(*tuples, charset: str = txt.CHARSET) -> list[str]:
|
2023-10-10 20:11:57 +00:00
|
|
|
process = subprocess.run(get_tuples_args(tuples), capture_output=True)
|
|
|
|
string = process.stdout.decode(charset)
|
|
|
|
return string.rstrip().splitlines()
|