I am attempting to run the ExcelToTable.py Geoprocessing script within a C# DropHandler class. The intent here is to allow the user to simply drop an Excel file containing attribute updates onto the map, and have the GP tool automatically handle the table import.
Going through the Geoprocessing samples, I see that since this GP tool is a python script, I cannot use the Geoprocessing.ExecuteToolAsync() method. Rather, I must use the Process.Start() method to run python scripts from within the ProSDK. Using the community samples snippet as a guide, I am able to get the ExcelToTable.py script to run, however I am unable to figure out how to pass the input file and output table parameters to the python script. In the community samples, there are no parameters being passed into the script, so I don't have an example to follow.
The code I have so far within the DropHandler class:
public override async void OnDrop(DropInfo dropInfo)
string InputFile = dropInfo.Items[0].Data.ToString();
string OutputTable = @"C:\Test\DropTest.gdb\Test1";
Debug.WriteLine($"File: {InputFile}");
// pro SDK snippet
var pathProExe = System.IO.Path.GetDirectoryName((new Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath)
if (pathProExe == null) return;
pathProExe = Uri.UnescapeDataString(pathProExe);
pathProExe = System.IO.Path.Combine(pathProExe, @"Python\envs\arcgispro-py3");
Debug.WriteLine(pathProExe);
var pathPython = @"C:\Program Files\ArcGIS\Pro\Resources\ArcToolBox\Scripts\ExcelToTable.py";
var myCommand = $@"/c """"{System.IO.Path.Combine(pathProExe, "python.exe")}"" ""{pathPython}""""";
Debug.WriteLine(myCommand);
var procStartInfo = new ProcessStartInfo("cmd", myCommand);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();
if (!string.IsNullOrEmpty(error)) result += string.Format("{0} Error: {1}", result, error);
System.Windows.MessageBox.Show(result);
The resulting Python error:
Which makes sense, since I never specified the Input file or output table. But at least this tells me that I am getting the script to start, albeit unsuccessfully.
procStartInfo.Arguments = "?"; // Do I pass the parameters here? If so, what is the syntax?
So in other words, what is the correct syntax for running the ExcelToTable.py script, given the string parameters of InputFile, and OutputTable? Do I use the above property of procStartInfo?
Thanks for your assistance!