This sort of question has been asked before in varying degrees, but I feel it has not been answered in a concise way and so I ask it again.
I want to run a script in Python. Let's say it's this:
def func1():
list = [1,2,3,4,5]
return list
Which gets the empty result.when putting print statement its return value to c#.but I want a result without printing in python. My actual code result is very big.so it takes time.
Okay, so how do I run this in C#?
This is what I have now:
var process = new Process () {
StartInfo = new ProcessStartInfo {
FileName = "python",
Arguments = "-u /home/varun/Desktop/data.py",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start ();
string output = process.StandardOutput.ReadToEnd ();
string error = process.StandardError.ReadToEnd ();
process.WaitForExit ();
if (string.IsNullOrEmpty (error)) { return output; } else {
Console.WriteLine (error);
return error;
}