3

Is it at all possible to build a Python GUI (lets say using Tkinter) and then pass the users input from the Python GUI into a windows batch file. My objective is to make batch files have a nice front end using Python.

Simple example:

In the Python code the user will be asked for a date

date = inputInt("Please enter Date yyyymmdd")  

Now I need to put this date value into a windows batchfile.

Sociopath
  • 13,068
  • 19
  • 47
  • 75
John
  • 321
  • 5
  • 16

2 Answers2

2

When running the the Python program you should use a pipe, to redirect it's stdout to stdin of the batch file. In the batch file you can just wait on the stdin until something is outputed by the Python program. Take a look here to see how to read an input stream in batch. It would look something like this:

python myprogram.py | batch_file.bat
AndrejH
  • 2,028
  • 1
  • 11
  • 23
0

I used the following code to send the data to a text file

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

I then used the following in my batch file to read the text file contents

@echo off
set /p startdate=<startdate.txt
echo %startdate%
John
  • 321
  • 5
  • 16