Question

I am developing wpf application. I am running the degrib.exe using the following code

 public static void GenerateCsvFile(string fileName)
        {
            try
            {
                MessageBox.Show("Csv Error");
                MessageBox.Show("File Name : " + fileName);
                MessageBox.Show("WorkingDirectory" + new FileInfo(fileName).DirectoryName);

                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = @"C:\ndfd\degrib\bin\degrib.exe";
                startInfo.Arguments = @"" + fileName + "" + " -C -msg 1 -Csv";
                startInfo.UseShellExecute = true;
                startInfo.WorkingDirectory = new FileInfo(fileName).DirectoryName;
                process.StartInfo = startInfo;
                process.Start();
                process.WaitForExit();
                process.Close();

                System.Diagnostics.Process process1 = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo1 = new System.Diagnostics.ProcessStartInfo();
                startInfo1.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo1.FileName = @"C:\ndfd\degrib\bin\degrib.exe";
                startInfo1.Arguments = @"" + fileName + "" + " -C -msg all -nMet -Csv";
                startInfo1.UseShellExecute = true;
                startInfo1.WorkingDirectory = new FileInfo(fileName).DirectoryName;
                process1.StartInfo = startInfo1;
                process1.Start();
                process1.WaitForExit();
                process1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Degrib Error");
                Utility.ShowErrorMessage(ex);
            }
        }

The degrib.exe produces the csv files from grib file. Here http://www.nws.noaa.gov/mdl/degrib/index.phpis the explanation of degrib. In the above function fileName is the path of the grib file. The above function crates the csv file from grib file if the grib file is placed in any folder other than Program Files. The same function will not produce the csv file if I have placed the grib file in Program Files or any other folder in Program Files. The same function is also not working with AppData folder. Why this is happening ? Can you please provide me any solution for the above issue ?

Was it helpful?

Solution

By default UAC in Vista or Win7 does not give applications write permissions in Program Files, unless they are launched with elevated access. you can do this by adding:

startInfo.Verb = "runas";

However, reading degrib manual i've noticed it accepts input and output parameters. So in your case it's recomended that you use a predefined location for your generated csv files. http://www.nws.noaa.gov/mdl/degrib/txtview.php?file=degrib.txt&dir=base

   -in [File]
     You can provide the file to read the GRIB message from either:
     1) right after "degrib",
     2) using the "-in [File]" option,
     3) on standard input.
   -out [File]
      Name of the file to store the results.  Must have 1 and only 1 dot in
      the name, and the extension must be 3 characters.  The extension will
      be replaced depending on file format.
   -namePath [Path]
      Name of a directory to put the files in.
      Only applicable if -out is NOT Specified.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top