1

this is a topic for somebody who may face similar thing in future. Once you try to schedule task in Windows using executable that was compiled with PyInstaller with option -noconsole and trying to use subprocess.check_output it does not work

Funny thing that if you call .exe directly then it works perfectly fine. However if you schedule a task or try to wrap execution into batch like:

C:\git\backend.exe -p C:\Users\settings.json

then it fails without any error code.
Only thing one can found is in tasks event log is error code: 2147942401

Beliaev Maksim
  • 968
  • 12
  • 21

1 Answers1

1

solution will be to explicitly specify Popen with stdin, out, err

p = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = p.stdout.read().decode('utf-8')
p.communicate()  

I found similar topics but just want to explicitly mention that by default command call or .exe double click it works but not from scheduled task

Inspired from here:
Pyinstaller issue with subprocess.check_output
Pyinstaller subprocess.check_output error
pyinstaller on Windows with --noconsole simply won't work

PS I always look for better solutions, if you have one, please suggest!

Beliaev Maksim
  • 968
  • 12
  • 21