在C#中将字符串作为批处理文件运行 [英] Running string as a Batch file in c#

查看:62
本文介绍了在C#中将字符串作为批处理文件运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个创建批处理文件的应用程序,然后运行:

I'm writing an application that creates a batch file and then run :

我知道我可以创建一个批处理文件并运行它 没问题.

I know I can create a Batch file and run it no problem with that .

我想做的是: 一旦创建了构成文件的字符串,是否有任何方法可以将 string 作为批处理文件执行? 像

What I want to do is : once I have created the string that makes the file , Is there is any way to execute the string as a Batch file ? something like

string BatchFile = "echo \"bla bla\" \n iperf -c 123  ... ... .. "
Diagnostics.Process.Start(BatchFile);

推荐答案

您可以使用/c 作为可执行文件运行 CMD.EXE ,并将其余部分作为参数:

You can run CMD.EXE with /c as an executable and have the rest as arguments :

Process.Start("cmd.exe", "/c echo \"bla bla\" \n iperf -c 123  ... ... .. ");

这篇关于在C#中将字符串作为批处理文件运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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