Python
class Thread(threading.Thread):
def __init__(self, name, sub):
threading.Thread.__init__(self)
self.name = name
self.sub = sub
def run(self):
while True:
if self.sub.poll() is not None:
break
command = bytes(str(input("console:").encode('utf-8')), encoding="utf-8")
# print(type(command))
#下面这句不会报错,也执行了,就是无效,跟没有这句一样为啥
self.sub.stdin.write(command)
is_input_started = False
while True:
empty = False
try:
enter = str(input('主文件路径:'))
except SyntaxError:
empty = True
if not empty:
if str(input('确定路径吗?(y,n):')) == 'y':
break
sub = subprocess.Popen(enter, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
if sub.poll() is not None:
print('Stopped')
break
out = sub.stdout.readline()
if not out == "":
print(out)
if not is_input_started:
thread = Thread.Thread('input', sub)
thread.start()
is_input_started = True
输入后并没有任何反应,怎么办
求助:Python的Subprocess.popen()返回的对象的stdin怎么用以下代码为何写入后没反应也不会报错
求助:Python的Subprocess.popen()返回的对象的stdin怎么用以下代码为何写入后没反应也不会报错
运行的程序是长时间一直运行
过程中需要互交于是这个问题就来了