0

Is there a way to get the python output in the shell from where i call the script? (Calling with the script name only, eg. PS>myscript.py)

More generally phrased: Is there a way to make > myscript.py behave like python myscript.py? And: What's the difference of what happens in the two cases? Why is calling the script directly being executed by a separate python process, and not as a subprocess within the shell? (That assumption of what's happening is probably wrong in concept and in wording, but i think that's what is happening.)

Why i bother: In PowerShell (or CMD), i can run PS>myscript.py from anywhere, because i added it's path to the PATH environment variable. Problem is, it will open a new window, that closes after execution. So i can't see the script output afterwards.

My first idea, calling python myscript.py needs more typing and more importantly, works only if myscript.py is a full path. A workaround to that would be to add the script to Python's modules path PYTHONPATH and then call it as a module: python -m myscript, but that's still more typing and more to remember, so still a workaround.

2
  • I'm pretty sure calling your script within python with subprocess.Popen will do what you want. Also, adding & cmd or & pause to the end of your command line should keep the second window open. Commented Oct 31, 2022 at 14:46
  • @OneMadGypsy, i can't follow any of your advice. Can you give full commandline examples? I got errors for > esptool.py & cmd and > python subprocess.Popen esptool.py Anyways, that would also still be a workaround. I am ideally lLookning for a way to make > myscript.py behave like python myscript.py Commented Nov 3, 2022 at 9:22

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.