Skip to content
Advertisement

Subprocess call with exit status 128

Essentially, I am trying to use a subprocess call to checkout a git commit at a specific sha hash.

However, I keep getting the error subprocess.CalledProcessError: Command '['git', 'checkout', '62bbce43e']' returned non-zero exit status 128.

This is my code below:

JavaScript

Advertisement

Answer

A subprocess.check_output() call actually returns the output (and you can also get error output as well by passing a stderr parameter). You may want to have a look at that to see if it gives you an error explaining what happened.

Since you’re getting an exception (meaning the call is not completing hence output may not be returned), you should be able to get the output from one of the exception members:

JavaScript

One thing I do know is that some git commands tend to return 128 if you’re not actually in a Git repo. So I’d be looking at the path following your cl("cd", repo) line, with:

JavaScript

If that cd of yours is running in a sub-process, that will not affect the current process and therefore you may not necessarily be in a Git repo at all. That would certainly explain the 128 return code.

By way of example, the following transcript shows what happens when I try to run a git command outside of a repo:

JavaScript

If it turns out you are in the wrong directory (i.e., the cl("cd", repo) statement is running a sub-process to change directory), you should use the Python-blessed method to change directories (a):

JavaScript

That actually changes the directory for the immediate process (the Python interpreter) rather than a transient sub-process.


(a) This is actually good advice in general – use Python-specific stuff as much as possible (since it’s mostly cross-platform) rather than spawning a sub-shell (which is inherently platform-specific).

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement