0

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 ?

Shailesh Jaiswal
  • 3,606
  • 13
  • 73
  • 124
  • User permissions. Run the process as admin. – leppie Dec 04 '12 at 08:45
  • you have to ask this to one who wrote degrib... – Tigran Dec 04 '12 at 08:46
  • 2
    @leppie: AppData, in my understanding, has to work even without admin permissions, as well. – Tigran Dec 04 '12 at 08:47
  • Have you used tools like [procmon](http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) to determine if the process was started? – Rowland Shaw Dec 04 '12 at 08:50
  • 1
    Most programs have an parameter which allows you to set the output path, perhaps grib has one too. In Windows newer than Vista ProgramFiles is not a place where you should change or store data (btw. MS is recommending to not use this location since long before Vista) – TGlatzer Dec 04 '12 at 08:53
  • One more thing about above issue - It does not produce any error. It does not go in catch block. But it is not able to create csv files – Shailesh Jaiswal Dec 05 '12 at 06:02

1 Answers1

0

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.
Bishan
  • 15,211
  • 52
  • 164
  • 258
ClotzA
  • 161
  • 7
  • I am having windows xp as os – Shailesh Jaiswal Dec 04 '12 at 11:17
  • Windows xp has similar behavior, except the fact that permission editing are hidden by default. goto Tools>Folder Options>View and uncheck "Use simple file sharing [Recommended]". Check that your WPF app has write permission. – ClotzA Dec 04 '12 at 14:44
  • Unchecked "Use simple file sharing [Recommended]". My WPF app has the write permission. I am successfully performing write operation for other files in the Application Data folder. I am able to perform all the required functionality in the Application Data folder. I am only not able to degrib the grib file with the above function – Shailesh Jaiswal Dec 05 '12 at 06:31
  • 1
    If your app has write permissions in Application Data but degrib.exe has none, you could bypass this by generating the csv file directly in degrib folder and move it to you AppData folder using System.IO.File.Move(sourceFile, destinationFile) . This is not an optimal solution but it will help you do your job. – ClotzA Dec 05 '12 at 10:52