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

Time:08-03

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

CodePudding user response:

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

CodePudding user response:

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

  • Related