I have a small problem. Okay let's say from my C# console application I want to run a batch file that will take an argument. The string variable at the stop of my C# application will be the string argument to pass to the batch file. How would I go about doing it?
我有一个小问题。好吧,让我们说从我的C#控制台应用程序中我想运行一个需要参数的批处理文件。我的C#应用程序停止的字符串变量将是传递给批处理文件的字符串参数。我该怎么做呢?
Here is my code so far my C# console program:
这是我的代码到目前为止我的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();
My Batch File
我的批处理文件
CLS
@ECHO OFF
ECHO %1
1 个解决方案
#1
0
You can give argument like this.
你可以给出这样的论点。
ProcessStartInfo psi = new ProcessStartInfo(filePath);
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.Arguments = "value1";
#1
0
You can give argument like this.
你可以给出这样的论点。
ProcessStartInfo psi = new ProcessStartInfo(filePath);
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.Arguments = "value1";