在C#中运行bat文件与.exe和.DEF code [英] Run bat file in c# with .exe and .def code

查看:184
本文介绍了在C#中运行bat文件与.exe和.DEF code的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能运行在C#中一个bat文件,它具有以下code:

  tekla_dstv2dxf.exe -cfg tekla_dstv2dxf_metric.def -m一批-f * .nc1

或可选择地复制了code在我的C#程序。
使用这种code执行bat文件,但该bat文件不起作用。

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

如果我通过程序双击它,只是没有BAT文件工作正常。

感谢


解决方案

好吧,算出来是偶然。低于code:

 的System.Diagnostics.Process PROC =新的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一批-f * .nc1
proc.Start();
proc.WaitForExit();

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

解决方案

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();

这篇关于在C#中运行bat文件与.exe和.DEF code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆