我有一个名为FW Tools的免费命令行工具。效果很好。以下是我在控制台窗口中输入的示例行: -
ogr2ogr -f "ESRI Shapefile" -a_srs "EPSG:26986" -t_srs "EPSG:4326"
towns_geodetic.shp TOWNSSURVEY_POLY.shp
我希望根据我动态生成的一些列表更改最后一个参数(我使用Linq-to-Filesystem并获取所有文件名),然后“n”次调用该程序。
我不关心输出。
可以这样做吗?
这完全属于.NET环境btw。
还有什么方法可以确保代码等待进程完成吗?
答案 0 :(得分:6)
我会采取更详细的方法来做这件事并做这样的事情
string ApplicationName = "ogr2ogr";
string BaseOptions = "-f \"ESRI Shapefile\" -a_srs \"EPSG:26986\"
-t_srs \"EPSG:4326\"";
//Start your loop here
ProcessStartInfo oStartInfo = new ProcessStartInfo()
oStartInfo.FileName = ApplicationName;
oStartInfo.Arguments = BaseOptions + MyLoopLoadedItemsHere;
Process.Start(oStartInfo)
//If you want to wait for exit, uncomment next line
//oStartInfo.WaitForExit();
//end your loop here
至少在我看来,这样的东西更具可读性。
答案 1 :(得分:5)
使用Process.Start。有点像...
Process.Start( "cmd /c Gregory -f \"ES RI Shape file\"
-a_Sirs \"PEGS:26986\" -t_Sirs \"PEGS:4326\"
towns_geodetic.Shep TOWNS SURVEY_PLOY.Shep" );
答案 2 :(得分:1)
我们去找我的朋友
Process.Start(@"C:\Windows\notepad.exe", @"C:\Windows\system.ini");
或
System.Diagnostics.Process.Start(@"C:\Windows\notepad.exe",
@"C:\Windows\system.ini");