0

I have installed odoo 8.0 (formerly openerp) source in my ubuntu 14.04
When i try this command (to run odoo server) from terminal

python odoo.py

it was run normally.

But, how can i know the return value of python command?
i want to see if the command running normally, or it is raise an exception?

So i can make *.sh file to run that command.

I have tried this code

if [ -f odoo.py ]; then
    python odoo.py
    rc=$?;
    if [ $rc !=0 ]; then
        echo "Error when starting odoo-server,"
        echo "Odoo-server not started."
    else
        sleep 1
        echo "Odoo-server started."
    fi
else
    echo "Cannot found odoo.py"
    echo "Odoo-server not started."
fi

but, when the command fail
it is always give me this output

Odoo-server started

Any one can help me?

2
  • See the config for the path of the logfile and read it. Commented Mar 10, 2016 at 7:41
  • How does Odoo fail? Does it throw an exception? Some other failure that causes it to just plain exit? If odoo.py just exits, is it documented to exit with a non-zero exit code? Commented Mar 10, 2016 at 7:44

1 Answer 1

2

Your spacing is wrong:

    if [ $rc !=0 ]; then

Should be:

    if [ $rc != 0 ]; then

But that is a text test, an arithmetic test would be:

    if [ $rc -ne 0 ]; then

or preferably:

    if (( rc != 0 )); then

However, a better way would be:

if python odoo.py
then
    sleep 1
    echo "Odoo-server started."
else
    echo "Error when starting odoo-server," >&2
    echo "Odoo-server not started." >&2
fi
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, i have tried your first solution and it work for me
But please note the better way to do it - there is no need to capture $? and test it explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.