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.

2 Answers 2

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
Sign up to request clarification or add additional context in comments.

1 Comment

There is a typo. Better to use pipes or you will overwrite the .bat script file: python myprogram.py | batch_file.bat
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%

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.