Forums

subprocess.call ('command.sh') returning error code 127 in django app while running ok in bash console

Hello, I need a django app to run a app. I installed the app (this one : https://cosma.arthurperret.fr/installing.html). It works fine while running in command line. But embedded in my django app, it does not work. subprocess.check_call returns :

subprocess.CalledProcessError: Command './cosma.sh' returned non-zero exit status 127.

I could not find answers in the other topics related to subprocess.call in the forum.

Thanks for any idea !

You need to use the full path to the executable.

Thank you for your answer. Even if I use the full path, it returns the same :

CalledProcessError at [view]

Command '[full path]/cosma.sh' returned non-zero exit status 127.

Any idea ?

See https://help.pythonanywhere.com/pages/NoSuchFileOrDirectory/#use-absolute-not-relative-paths

Thanks. The error occurs even while I am using absolute path.

It looks like you just used the text [full path] instead of the actual path to the file. You need to use the actual path to the file, not a placeholder.

No, I wrote full_path in this forum post, but in my code I did write the full path :

subprocess.check_call('/home/graphe/graphe/static/cosma/cosma.sh')

and the server returns an error :

subprocess.CalledProcessError: Command '/home/graphe/graphe/static/cosma/cosma.sh' returned non-zero exit status 127.

That cannot be the correct full path. Your username is experience so, at the very least, the path needs to start with "/home/experience". If that is incorrect, then the rest may not be, too. Find the binary that you want to run and then use the path to the that in your code.

I have another account, graphe, on eu.pythonanywhere.com. The error occurs on that account, with the full path.

The path to the binay is :

/home/graphe/.nvm/versions/node/v24.14.0/bin/cosma

The command I would like to launch is :

cosma modelize

Sorry if I am missing something. Thank you very much for your help

If the path that you just specified is /home/graphe/.nvm/versions/node/v24.14.0/bin/cosma then you need to use that, and not /home/graphe/graphe/static/cosma/cosma.sh

That did not work either.

I finally found a solution : to copy the env['PATH'] from the bash console to the subprocess command :

import os

env = os.environ.copy()

env['PATH']= '/home/graphe/.virtualenvs/bulle313/bin:/home/graphe/.local/bin:/home/graphe/.nvm/versions/node/v24.14.0/bin:/usr/local/julia-1.10.4/bin:/usr/lib/postgresql/16/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

subprocess.call(["/home/graphe/node_modules/.bin/cosma", "modelize"], cwd="/home/graphe/graphe/static/cosma", env=env)

It works !