because of the way my hoster does things I have to use a system for services.

This service has a run file which it executes and pipes into a second run file. But I use a (given) python package that logs to stderr instead of stdout and I can't get it to do what I want.

So I have a run script for my service:

cd ~/webapp/PriceList
exec python3.4 ~/webapp/PriceList/src/main.py

which is piped into the run of the logging system:

exec multilog t ./main

But the pipe doesn't connect stderr (as expected). So after googling I appended a redirection to my run:

cd ~/webapp/PriceList
exec python3.4 ~/webapp/PriceList/src/main.py 2>&1

But this does not solve my problem: My own outputs (to stdout using pythons print) are logged as expected. The stderr output is not logged.

If I redirect my modified runscript into two files, it shows that there is no redirection (stderr is still on stderr). How do I have to modify my redirection to work?

closed as unclear what you're asking by Stephen Rauch, Scott, Romeo Ninov, Anthon, Anthony Geoghegan Jul 21 '17 at 8:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    exec ... 2>&1 does indeed join standard error into standard out. So something else is awry. – thrig Jun 17 '16 at 17:37
  • 3
    Any chance the python script is closing stderr and re-opening it as a file? Look for a call to dup2() in the code. Any idea where the stderr output is going? Another thought: perhaps your hoster's run file is redirecting stderr this way before starting your code. – Edward Falk Jun 23 '16 at 4:30
  • 1
    Can you absolutely confirm that text is being sent to stderr? Replace the script with one that says import sys; print("Hello, stderr", file=sys.stderr) to be sure. – rosuav Feb 24 '17 at 23:54
  • 3
    Really stderr? Try this exec python3.4 ~/webapp/PriceList/src/main.py > out.log 2> err.log and take a look into this logfiles. – ingopingo Feb 26 '17 at 15:39
  • 2
    What happen if you use bash instead of sh? – Luciano Andress Martini Apr 25 '17 at 14:54

Please try:

#!/usr/bin/env bash
exec 2>&1
cd ~/webapp/PriceList
exec python3.4 ~/webapp/PriceList/src/main.py

ie : exec 2>&1 on a separate line, telling to redirect stderr to the same thing stdout is going to (your terminal? or mail if in a crontab?), followed by the cd & exec to replace the existing process with the python3.2 one. Note that I switched to bash instead of sh, for a lower portability but usually a much better reliability. If this works, great, if not some better knowledgeable persons will step in. (I don't have time to do researchs right now on this)

Not the answer you're looking for? Browse other questions tagged or ask your own question.