3 回答
TA貢獻1951條經驗 獲得超3個贊
定期檢查文件大?。?/p>
import os
import time
log_path = '/tmp/com1.log'
special_word = 'magic'
lastsize = 0
while 1:
if os.path.exists(log_path) and os.path.getsize(log_path) > lastsize:
with open(log_path) as f:
f.seek(lastsize)
for line in f:
if special_word in line:
print('Special word found')
lastsize = f.tell()
time.sleep(1)
TA貢獻1757條經驗 獲得超8個贊
您可以使用teraterm的宏語言,它允許開發人員擴展teraterm的行為。
對于您的特定情況,Teraterm的宏語言提供了wait系列功能,以等待特定的單詞(或)模式序列。請注意,teraterm宏語言不是python,但是它具有自己的語法。
; wait for special world 'hello'
wait 'hello'
if result == 0 goto your_own_logic
還有其他方法,如果您想擁有僅適用于python的解決方案。您可以使用pyserial python庫與串行端口連接,而不是使用teraterm與串行端口連接。
添加回答
舉報
