Run bat file in c# with .exe and .def code

北城以北 提交于 2019-12-08 11:54:17

问题


How can I run a bat file in C# that has the following code:

tekla_dstv2dxf.exe -cfg tekla_dstv2dxf_metric.def -m batch -f *.nc1

or alternatively replicate that code in my c# program. Using this code executes the bat file but the bat file doesn't work.

System.Diagnostics.Process.Start(@"C:\0TeklaBatchProcess\1-SCAD_Issue_Processing\DXF\tekla_dstv2dxf_metric_conversion.bat");

The bat file works fine if I double click it, just not through my program.

Thanks


回答1:


You can specify the command arguments directly in the Start method parameters:

Process.Start("IExplore.exe", "www.northwindtraders.com");

so

Process.Start("tekla_dstv2dxf.exe", "-cfg tekla_dstv2dxf_metric.def -m batch -f *.nc1");

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx




回答2:


Use System.Diagnostics.ProcessStartInfo




回答3:


Ok, worked it out by chance. Code below:

System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = "tekla_dstv2dxf.exe";
proc.StartInfo.RedirectStandardError = false;
proc.StartInfo.RedirectStandardOutput = false;
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.StartInfo.WorkingDirectory = @"C:\0TeklaBatchProcess\1-SCAD_Issue_Processing\DXF";
proc.StartInfo.Arguments = @"-cfg tekla_dstv2dxf_metric.def -m batch -f *.nc1";
proc.Start();
proc.WaitForExit();


来源:https://stackoverflow.com/questions/4466136/run-bat-file-in-c-sharp-with-exe-and-def-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!