0

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

Mutley
  • 77
  • 2
  • 13

3 Answers3

2

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

AndyElastacloud
  • 625
  • 5
  • 21
0

Use System.Diagnostics.ProcessStartInfo

mharr
  • 594
  • 5
  • 12
0

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();
Mutley
  • 77
  • 2
  • 13