Issue 34615: subprocess.call wrong exit code (original) (raw)

Hello there,

I am probably confusing myself. I am using this kind of code in Nuitka to emulate "os.execl" on Windows, and so far it never let me down:

        r = subprocess.call(
            args,
            shell = False
        )

        print (r, args)

        sys.exit(r)

When i execute my tests with Nuitka and Python 3.6 and everything before, this gives:

1 ['test_call.exe'] 1 ['C:\Python36_32\python.exe', '-S', '..\..\nuitka\main.py', '--run', 'test/test_call.py']

And with python 3.7 it gives:

0 ['test_call.exe'] 0 ['C:\Python37_32\python.exe', '-S', '..\..\nuitka\main.py', '--run', 'test/test_call.py']

So I am in Nuitka re-executing itself without the site module, and then immediately the created binary. For 3.7 it doesn't give me an error. I manually confirmed that "test_call.exe" indeed gives error code 1 as well, in both bash and cmd.exe, but it is not seen in the return value. Checking existing issues, I didn't find any hint at all, how this can be. I added "shell = False" to make it clear that no "cmd.exe" should be used, for which there had been issues.

I also confirmed, by adding a exit(27), that if I simulate that "test_call.exe" gave 27, rather then 0, then that one is detected by the exec, so what could be going on here. But I am also sure I don't confuse binaries or so, plus it's working as expected in other Python versions than 3.7.0 here.

This happens with 64 bits too, I am only citing 32 bits. And it is happening with just about every compiled unit test that gives an error exit, where otherwise e.g. tests that check for error exits to be the case work nicely.

Thanks for any help or direction you can give me there. I am at loss.

Yours, Kay

I think that the whole reason I was doing this, is because with "os.execl" on Windows, the exit code was always lost, but of course it is very important and "subprocess.call" promises to return it.

I just tried if 3.7 has any better exit code handling right there for "os.execl", but apparently it's not the case.

So I was confused indeed.

Actually I am observing in other tests at least, that apparently Nuitka compiled execution in my tests can import _testcapi module, which normal execution of the test does not manage.

Then there is the possibility that the exit code is indeed "0" and different.

The failure to import that module is old, and something I consider to raise as a separate issue. Closing this one as it's not worthy.