Run Python excutable ( compiled using pyinstaller ) in powershell and save the output in variable

Question:

Run Python excutable ( compiled using pyinstaller ) in powershell and save the output in variable.
I have a python exe ( compiled using pyinstaller ) , and would like to save the output of main.exe in a powershell variable . How should i call it ? Just running main.exe and assigning a variable always comes as empty or null.

enter image description here

even the simple attached code is not working :
enter image description here

Asked By: Prithijit Majumdar

||

Answers:

At firts, go in your .py file and import sys
This module is in the Python Standard Library, so you don’t have to install it.

Then, at the end of the file, include sys.stdout.write(), passing it the value you want to save.

Recompile your program using pyinstaller.

Open the powershell, and move to the directory you saved the main.exe file

Launch $VariableName = main

  • Edit after discussion

Do this:

def getpwdtoconnect():
   pwdtoconnect = getSecret('kevy', 'test')
   return pwdtoconnect

sys.stdout.write(getpwdtoconnect())
Answered By: Nicolò Teseo

Issue was with using noconsole parameter of pyinstaller. –noconsole should not be used if the output needs to be returned.

Answered By: Prithijit Majumdar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.