Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does output redirection not work in this case?

Tags:

linux

bash

shell

OS is ubuntu12.04. I wrote a python program main.py, and wanted to run it easily. So I created the following shell script called run.sh.

#!/bin/bash

python main.py & >/dev/null  2>&1

And executed this command chmod u+x run.sh.

However, when I ./run.sh, the python program's output is still there in the terminal.
But this can work: ./run.sh >/dev/null 2>&1. But this way is against my original intention, since it's too complex to use.

I wonder why this could happen. And how can I achieve my intention?

like image 277
particle128 Avatar asked Feb 14 '26 11:02

particle128


1 Answers

If you want to run script at the background try this:

python main.py >/dev/null  2>&1 &
like image 65
vahid abdi Avatar answered Feb 15 '26 23:02

vahid abdi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!