我在试着做一个决定
terminal
使用时
Replit
(基于浏览器的协作IDE)使用
Ubuntu 5.13.12
但是,由于某些原因,子流程不接受列表/元组来运行它。我试着用
os.system
但我意识到它只会在使用字符串时返回一个值。
上面显示的代码只适用于类似Linux的发行版
Ubuntu
,
Fedora
,
Debian
.
Python简化终端
import termcolor;
import subprocess;
import os;
while (__name__ == '__main__'):
_DEPENDENT_PROCESS = []
_STRING_DIVISOR = " "
terminal_input = input(termcolor.colored(os.path.dirname(os.path.realpath(__file__)), "blue", attrs=['bold']) + "$ ")
if _STRING_DIVISOR in terminal_input:
counted_arguments = terminal_input.count(_STRING_DIVISOR)
splited_arguments = list(terminal_input.split(_STRING_DIVISOR, counted_arguments))
_DEPENDENT_PROCESS, error = splited_arguments, None
intrepeter = subprocess.run([_DEPENDENT_PROCESS], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
_terminal_output = intrepeter.stdout
print(_terminal_output.decode('ascii'))
Error: Expected str, bytes, os.Paths, not lists