2012-12-04 38 views
0

我正在开发wpf应用程序。我使用以下代码运行degrib.exe为什么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文件放入程序文件或程序文件中的任何其他文件夹,相同的功能将不会生成csv文件。相同的功能也不适用于AppData文件夹。为什么发生这种情况?你能为我提供解决上述问题的任何解决方案吗?

+0

用户权限。以管理员身份运行进程。 – leppie

+0

你必须问这个谁写了degrib ... – Tigran

+2

@leppie:根据我的理解,即使没有管理员权限,AppData也必须工作。 – Tigran

回答

0

默认情况下,UACVistaWin7不会为程序写入权限,除非它们使用提升的访问权限启动。 您可以通过添加做到这一点:

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. 
+0

我有Windows XP作为操作系统 –

+0

Windows XP具有类似的行为,除了权限编辑默认情况下隐藏的事实。转到工具>文件夹选项>查看并取消选中“使用简单文件共享[推荐]”。检查您的WPF应用程序是否具有写入权限。 – ClotzA

+0

未选中“使用简单文件共享[推荐]”。我的WPF应用程序具有写入权限。我正在成功执行Application Data文件夹中其他文件的写入操作。我能够在Application Data文件夹中执行所有必需的功能。我只能用上述函数去掉grib文件 –

相关问题