Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Last active March 4, 2023 17:56
Show Gist options
  • Save MatthewJDavis/ba97157071ed2bc8cdfaa0432b3448f7 to your computer and use it in GitHub Desktop.
Save MatthewJDavis/ba97157071ed2bc8cdfaa0432b3448f7 to your computer and use it in GitHub Desktop.
Example on how to call a Python script and save the output of the print statement to a variable.
# Calls a Python script. The output of the print statement is saved in a Variable.
$pythonProgramPath = ".venv/bin/python" # location of the Python executable
$pythonScriptPath = "/python/powershell-call-python/main.py" # location of script file.
$arg = "hello"
$pythonOutput = & $pythonProgramPath $pythonScriptPath $arg
$pythonOutput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment