0

I am working with Python3.7.0 on a Windows 10 machine.

I have a program that runs every 5 minutes through task scheduler and if certain parameters are met (it is a given time of day), I require user input. Otherwise, the program is ended.

Every 5 minutes, even if no user input is required, a python window pops open because the program is run through python.exe.

To avoid this problem, is there a way to run the script through pythonw.exe and open a terminal only when user input is required?

The code that I would need would be something that functions as the sudo-code below:

if (conditions are met):
    open terminal window
    run program in terminal window
    close terminal window
else:
    do nothing
YosiFZ
  • 7,792
  • 21
  • 114
  • 221
HellsMayo
  • 1
  • 2

2 Answers2

0

From the pseudocode it seems that if the conditions are not met the program does nothing.

I would suggest that your solution is not correct, and you should rather make sure that the program is only run when you want, windows scheduler supports that easily, refer to the documentation.
You did not provide detail about how your task is set up, but documentation has examples for scripting, c++ and XML to run a task at a specific time every day here.

m1n0
  • 609
  • 5
  • 16
0

To open a terminal and run batch commands execute the bash commandstart cmd.exe /k "more-batch-commands-here" as a subprocess or use os module.

process = subprocess.Popen(
    '''start cmd.exe /k "more-batch-commands-here"''', 
    stdout=subprocess.PIPE,
    stderr=None,
    shell=True
)

Edit : Didn't notice that no user-input is required.

This is not the exact answer you are looking for. To open an input window:

from tkinter import simpledialog
str_ = simpledialog.askstring("Title","Enter a string:")

Caveat is this might not work well with all kinds of machines. But for Windows 10 this should work fine.

Nihal Sangeeth
  • 5,168
  • 2
  • 17
  • 32