Home > Back-end >  Script progress messages from python when executing script from powershell
Script progress messages from python when executing script from powershell

Time:03-22

I have a powershell script that begins by calling a python script. Everything works fine and it's doing everything I want it to do. I just want to know if I can get stdout or print messages from python to display in powershell, similar to verbose messages. Right now the python script runs for a minute or so. I do have a powershell comment that says "running the python..." so there is at least some message, but I'd like to be able to essentially print verbose messages from python in real time too. From what I can tell, it's only possible to just dump all those messages to powershell when the python script has finished executing, but I want to know about doing it in real time. Is this a thing I can do? Thanks.

CodePudding user response:

First, you need to know that you can run scripts asynchronously via Powershell: Run a separate PowerShell script asynchronously while continuing the current script

However, you are also able to create a subprocess in order to run the script, which will not block your main thread: How to execute a bunch of shell commands serially without blocking the main thread?

You can also capture shell output: Running shell command and capturing the output

However, if the above is not enough, that is, if the shell script is not providing the information you need while it is running, then you will need to get creative and find a way of doing measurements. E.g. if it is the copying of a folder to another place, then you can regularly measure the target folder's size.

  • Related