我正在用C#开发wpf应用程序。我在我的应用程序中使用grib文件。我想把这个grib文件的内容转换成csv文件。从命令提示符我可以很容易地做到这一点。为此,在命令提示符下,我需要转到degrib.exe的文件夹位置,即c:\ndfd\degrib\bin。对于任何其他路径,命令将不会执行。我正在使用以下命令
C:\ndfd\degrib\bin\degrib D:\Documents\Pacificwind.grb -C -msg 1 -Csv
C:\ndfd\degrib\bin\degrib D:\Documents\Pacificwind.grb -C -msg all -nMet -Csv命令成功执行。我可以在C:\ndfd\degrib\bin文件夹中看到生成的csv文件。我应该如何从C#执行相同的命令。我见过不同的例子,但没有一个对我有效。您能提供给我任何代码或链接,我可以通过它来解决上述问题吗?
发布于 2012-09-28 17:14:54
这将起作用,除非您提供的路径不正确:
Process.Start(@"C:\ndfd\degrib\bin\degrib",
@"D:\Documents\Pacificwind.grb -C -msg 1 -Csv");
Process.Start(@"C:\ndfd\degrib\bin\degrib",
@"D:\Documents\Pacificwind.grb -C -msg all -nMet -Csv")发布于 2012-09-28 17:14:13
您可以使用ProcessStartInfo类为启动的应用程序设置工作目录。
例如
ProcessStartInfo pInfo = new ProcessStartInfo("degrib.exe");
pInfo.WorkingDirectory = @"C:\ndfd\degrib\bin"
pInfo.Arguments = @"D:\Documents\Pacificwind.grb -C -msg 1 -Csv";
Process p = Process.Start(pInfo);
// Are I assume that the second processing need to wait for the first to finish
p.WaitForExit();
// Start the second run.....
pInfo = new ProcessStartInfo("degrib.exe");
pInfo.WorkingDirectory = @"C:\ndfd\degrib\bin"
pInfo.Arguments = @"D:\Documents\Pacificwind.grb -C -msg all -nMet -Csv";
Process.Start(pInfo);另请查看有关Process类和WaitForExit方法的文档
编辑:我真的不知道它是什么degrib,现在我已经更新了你想要得到的合理假设的答案。请告诉我路径和可执行文件名称是否正确。
发布于 2012-09-28 17:15:54
您可以使用以下方法来执行您的exe文件
System.Diagnostics.Process.Start(exePath + "LSAPP.exe");https://stackoverflow.com/questions/12636991
复制相似问题