0

We know that we can run python functions in c# and invoking the console and we can get python output in c# in the python console but whats the use of that if we cannot the python output as the c# input ? it would be useless integration so my question is : how do you retrieve python output as c# input ? can you import variables from python to c#? how do you that ?

I'm calling python function in c# and the out put is still in python console but can it be used in c# for example if I return python function in c# can i declare it as variable to use it in my c# program ?

that's all thank you help me :)

Saverio Terracciano
  • 3,885
  • 1
  • 30
  • 42
  • Could you explain a bit better what you are trying to do? It seems you might be running python in a separate shell. You could look into the `Process` class that lets you redirect `STDOUT`. Or, you could look into IronPython for a .NET version of Python. – Daren Thomas Feb 27 '14 at 07:40
  • im trying to get the python output and use it in c# as input – user3308595 Feb 27 '14 at 07:44
  • well... how are you producing the output? show me some code please. – Daren Thomas Feb 27 '14 at 09:44
  • right now i just can call python function through c# and the output will be produced into the popped up python console that means by calling the function the c# calls the console as well through the engine function that is available – user3308595 Feb 28 '14 at 06:32

1 Answers1

0

Take a look at the Process.Start method. It takes a ProcessStartInfo argument that lets you redirect standard output - this is what gets printed to the console when you print "hello, world!" in python.

Check this question here for more information on how to do it: How to spawn a process and capture its STDOUT in .NET?

Community
  • 1
  • 1
Daren Thomas
  • 67,947
  • 40
  • 154
  • 200