How do I get a return value when calling GPSBabel from C#

المشرف العام

Administrator
طاقم الإدارة
I have some C# code that calls a GPSBabel command line to convert a NMEA file to a GPX file. The code works and the conversion happens. The problem is, how do I get a return value indicating success or failure?

When an error occurs, the message appears in the console window but nothing is sent to the console via Console.WriteLine(output.ToString());. An error appears in the console when the input file can't be found but nothing enters in the stream or stringbuilder.

I need to tell if the conversion worked. I need to know if the output file was created and when writing to that output file is complete. If I can't get a return code from GPSBabel, how can I tell if the command worked? I could roll my own status indicator if necessary - instead of outputting the stringbuilder, check if the output file was created, if it was, check if I can get read-write access, etc.

static void Main(string[] args){ string cmdArgs = "-i nmea -f sample.nmea -o gpx -F output.gpx"; StringBuilder output = new StringBuilder(); ProcessStartInfo start = new ProcessStartInfo(); start.FileName = @"C:\GPSBabel_1.5.2\gpsbabel.exe"; start.Arguments = string.Format("{0}", cmdArgs); start.UseShellExecute = false; start.RedirectStandardOutput = true; using (Process process = Process.Start(start)) { using (StreamReader reader = process.StandardOutput) { string tmp = reader.ReadToEnd(); output.Append(tmp); } } Console.WriteLine(output.ToString()); Console.WriteLine("\n\n\nDone... "); Console.ReadLine();}

أكثر...
 
أعلى