[英]Execute a Batch File From C#
我有一个小问题。 好吧,让我们说从我的C#控制台应用程序中,我想运行一个带有参数的批处理文件。 在我的C#应用程序的结尾处的字符串变量将是传递给批处理文件的字符串参数。 我将如何去做?
到目前为止,这是我的C#控制台程序的代码:
//String argument to pass to the batch file
string message = "Hello World";
System.Diagnostics.Process process = new System.Diagnostics.Process();
//startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "Greetings.bat";
startInfo.Arguments = "/C " + message;
process.StartInfo = startInfo;
process.Start();
我的批处理文件
CLS
@ECHO OFF
ECHO %1
你可以这样说。
ProcessStartInfo psi = new ProcessStartInfo(filePath);
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.Arguments = "value1";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.