是否有可能构建Python GUI(例如使用Tkinter
),然后将Python GUI
的用户输入传递到Windows批处理文件中。
我的目标是使用Python使批处理文件具有良好的前端。
简单的例子:
在Python代码中,将要求用户输入日期
date = inputInt("Please enter Date yyyymmdd")
现在,我需要将此日期值放入窗口batchfile
中。
答案 0 :(得分:2)
运行Python程序时,应使用pipe将其stdout
重定向到批处理文件的stdin
。在批处理文件中,您只需等待stdin
,直到Python程序输出了某些内容。看一下here,了解如何批量读取输入流。看起来像这样:
python myprogram.py | batch_file.bat
答案 1 :(得分:0)
我使用以下代码将数据发送到文本文件
observeSingleEvent
然后我在批处理文件中使用以下内容读取文本文件内容
import sys
startdate = input("Please Enter StartDate YYYYMMDD ")
orig_stdout = sys.stdout
f = open('startdate.txt', 'w')
sys.stdout = f
print(startdate)
sys.stdout = orig_stdout
f.close()