0

I'm currently working with Python and Bash to run a backend of a web application. I've inhereted this project and am tasked to do modifications on it, therefore I don't have a good knowledge about what the person who wrote this code had intended to do, so sorry if my question seems a bit disconnected at places.

What I'm currently doing is using Python to call a subprocess via .Popen() which executes a Bash Script, after that, I use .communicate() on the return value of this subprocess to gather the stdout and stderr from it, if the later is not empty, I run checks on what it contains and act further accordingly. However, it doesn't appear clear to me what kind of error is written into "stderr". Shouldn't an "exit 1" for example be logged in stderr? Does stderr only concern itself with errors that occur while executing .Popen()? And is there a way to have an error logged in stderr from inside the Bash Script that is being run?

Jan I.
  • 1
  • Only those who can see the bash script can know for sure. Please search the web for the fundamentals on output redirection in bash. Once you have a grasp of that you can begin to understand how your python script interacts with the bash script. – Tobias Fendin Jan 27 '21 at 11:53
  • `exit` does not print anything to standard error, but will reflect on the exit code (what you get from `p.wait()`). Unless you require the subprocess to run concurrently with your Python program, you should probably use `subprocess.run()` or similar, instead of directly talking to the low-level `Popen()` function. – tripleee Jan 27 '21 at 12:38

0 Answers0