使用 .exe 和 .def 代码在 C# 中运行 bat 文件

发布于 2024-10-08 08:43:18 字数 381 浏览 0 评论 0原文

如何在 C# 中运行包含以下代码的 bat 文件:

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

或者在我的 c# 程序中复制该代码。 使用此代码执行bat文件,但bat文件不起作用。

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

如果我双击该bat文件,它就可以正常工作,只是不是通过我的程序。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

策马西风 2024-10-15 08:43:18

您可以直接在 Start 方法参数中指定命令参数:

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

所以

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

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

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

说谎友 2024-10-15 08:43:18

使用 System.Diagnostics.ProcessStartInfo

Use System.Diagnostics.ProcessStartInfo

哆兒滾 2024-10-15 08:43:18

好吧,偶然发现的。代码如下:

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

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文