0

我正在开发 wpf 应用程序。我正在使用以下代码运行 degrib.exe

 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);
            }
        }

degrib.exe 从 grib 文件生成 csv 文件。这http://www.nws.noaa.gov/mdl/degrib/index.php是degrib的解释。上面函数fileName中是grib文件的路径。如果 grib 文件放置在 Program Files 以外的任何文件夹中,则上述函数会从 grib 文件中创建 csv 文件。如果我将 grib 文件放在 Program Files 或 Program Files 中的任何其他文件夹中,相同的函数将不会生成 csv 文件。同样的功能也不适用于 AppData 文件夹。为什么会这样?您能为我提供上述问题的任何解决方案吗?

4

1 回答 1

0

默认情况下UACVistaWin7不授予应用程序在 Program Files 中的写入权限,除非它们以提升的访问权限启动。您可以通过添加:

startInfo.Verb = "runas";

但是,阅读degrib手册我注意到它接受输入和输出参数。因此,在您的情况下,建议您为生成的 csv 文件使用预定义的位置。 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.
于 2012-12-04T10:30:23.407 回答