I am in the process of migrating various add in applications to Pro 3.0 and am encountering grief with running a python script from my Pro Application.
I have relied on a method that calls the "propy.bat' routine to run the python script. This has always worked well in the Pro 2.x series under the various .NET Frameworks. I am assuming the .NET core is introducing a twist into this.
As a base test to make sure the python script itself was functioning in my Pro 3.0 environment, I ran the script interactively in Pro through the Python window and it worked.
When I am running the application and calling the script through propy.bat, it never returns a value. I have monitored this in Task Manager and can see the Python task begin and start to consume cpu. However,
it never returns a value and the python task in task manager remains consuming 0 percent cpu.
I have tried tweaking the statements of how the process is called, by simply starting it, without using the "ReadToEnd" of the standard output. This resulted in script successfully running. However in this configuration, I am unable to 'wait' for it in the application and the python code. I have looked around a bit on the internet and have tried to implement some different approaches with no luck.
The following method is how I have successfully been calling it at 2.x under the 'old' frameworks. In the brave new 3.0 / .Net core world, it processes "result = reader.ReadToEnd();" and never returns. The expected outputs of the python file are not created.
public async Task<string> run_arcpyReturnSurfaceProcessingResultsString(string pythonFile)
{
string result = "";
await QueuedTask.Run(() =>
{
GC.Collect();
ProcessStartInfo start = new ProcessStartInfo();
start.CreateNoWindow = true;
start.FileName = @"c:\Program Files\ArcGIS\Pro\bin\Python\scripts\propy.bat";
start.Arguments = string.Format("{0}", pythonFile);
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using (Process process1 = Process.Start(start))
{
using (StreamReader reader = process1.StandardOutput)
{
result = reader.ReadToEnd();
reader.Close();
process1.Close();
return result;
}
}
});
return result;
}
Any insight would be welcome.