Skip to content

Commit

Permalink
成功且正确地逐行读取正在运行的程序的输出。已测试,已启动时可以完成切换但无法启动第二个,启动器本身的限制。
Browse files Browse the repository at this point in the history
  • Loading branch information
LiuJiewenTT committed Jan 31, 2024
1 parent 8c19ce7 commit e6cdee5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
venv
keep_local
.idea
__pycache__
10 changes: 7 additions & 3 deletions src/CBJQ_SS_FrontEnd_tk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,21 @@ def execAction(self, **kwargs):
with subprocess.Popen(launch_cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8') as sp:
self.displayLog_text.insertAndScrollToEnd(f'sp.pid: {sp.pid}')
self.displayLog_text.insertAndScrollToEnd('[+]' + '运行报告' + '-' * 15)
while sp.poll() is None:
while True:
# print('to read')
# output = sp.communicate(timeout=1)[0]
output = sp.stdout.readline()
try:
output = sp.stdout.__next__()
except StopIteration:
break
# output = sp.stdout.readline()
# print(f'[stdout]: {i}', end='')
# self.displayLog_text.insert('end', i)
# self.displayLog_text.yview_moveto(1)
self.displayLog_text.insertAndScrollToEnd(output, end='') # instance method
# self.displayLog_text.update()
print('')
self.displayLog_text.insertAndScrollToEnd('[-]' + '运行后报告' + '-' * 15)
self.displayLog_text.insertAndScrollToEnd('[-]' + f'运行后报告(pid: {sp.pid})' + '-' * 15)
self.displayLog_text.insertAndScrollToEnd('[-]' + '' + '=' * 15)
pass

Expand Down

0 comments on commit e6cdee5

Please sign in to comment.