WinForm可以执行控制台程序吗?如果是这样,怎么样?

Pur*_*ome 1 .net command-line

我有一个名为FW Tools的免费命令行工具.效果很好.以下是我在控制台窗口中输入的示例行: -

ogr2ogr -f "ESRI Shapefile" -a_srs "EPSG:26986" -t_srs "EPSG:4326"
    towns_geodetic.shp TOWNSSURVEY_POLY.shp
Run Code Online (Sandbox Code Playgroud)

我想改变最后的参数,基于我动态生成的一些列表(我使用Linq-to-Filesystem并获取所有文件名)然后调用该程序'n'次.

我不关心输出.

可以这样做吗?

这完全是在.NET环境下btw.

编辑

是否还有任何方法可以确保代码等待进程完成?

Mit*_*ers 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
Run Code Online (Sandbox Code Playgroud)

这样的东西更具可读性,至少在我看来是这样.


JP *_*oto 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" );
Run Code Online (Sandbox Code Playgroud)

以下是一些如何更清洁的例子.