将Python输入参数传递到批处理文件

时间:2018-07-27 06:31:49

标签: python-3.x

是否有可能构建Python GUI(例如使用Tkinter),然后将Python GUI的用户输入传递到Windows批处理文件中。 我的目标是使用Python使批处理文件具有良好的前端。

简单的例子:

在Python代码中,将要求用户输入日期

date = inputInt("Please enter Date yyyymmdd")  

现在,我需要将此日期值放入窗口batchfile中。

2 个答案:

答案 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()