3

I have an external C# program which executes a Python script using the Process class.

My script returns a numerical code and I want to retrieve it from my C# program. Is this possible?

The problem is, I'm getting the return code of python.exe instead of the code returned from my script. (For example, 3.)

1 Answer 1

8

The interpreter does not return the value at the top of Python's stack, unless you do this:

if __name__ == "__main__":
    sys.exit(main())

or if you make a call to sys.exit elsewhere.

Here's a lot more documentation on this issue.

Sign up to request clarification or add additional context in comments.

1 Comment

2.7.9 documentation for sys.exit().

Your Answer

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