2012-12-04 35 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文件 –

相關問題