问题
We have a C# module that needs to pass XML as a string to a python module and get the process result from that python module (has complicated logic and many imported libraries). But somehow I got nothing returned after several tries, the following is my sample code. Also is that possible to use pyinstaller to package the python module into EXE and achieve same functionality?
public InquiryResponse ProcessXML(string xml)
{
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"C:\Python\python.exe";
psi.Arguments = string.Format(@"C:\myapp.py" {0}", xml);
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
var error = "";
var result = "";
using (var process = Process.Start(psi))
{
error = process.StandardError.ReadToEnd();
result = process.StandardOutput.ReadToEnd();
}
// Some other process
}
来源:https://stackoverflow.com/questions/61059829/call-python-scripts-with-many-dependent-libraries-from-c-sharp-code