1

I have a C# program which executes a python scrip

How can I retrieve the python returning value in my C# program ?

thanks!

2
  • Do you mean the exit code, which is just an integer value, or a more elaborate value, like a string? Commented Aug 3, 2009 at 8:00
  • an integer, which indicates if the python script ran successfuly. Commented Aug 3, 2009 at 8:04

2 Answers 2

2

As far as I know, you should use ScriptScope object which you create from the ScriptEngine object using CreateScope method

ScriptEngine engine = ScriptRuntime.Create().GetEngine("py");
ScriptScope scope = engine.CreateScope();

Then you can share variables between the C# program and the python script by doing this

scope.SetVariable("x", x);
Sign up to request clarification or add additional context in comments.

2 Comments

I assume this is only for IronPython? Still interesting though.
Yes this is for both IronPython & IronRuby, I thought you meant Iron Python in the first place :)
1

if your using System.Diagnostics.Process to launch your python script, then you can get the return code after process exit

using

process.ExitCode

Comments

Your Answer

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