C# 从文本框打开命令并将命令写入cmd

C# 从文本框打开命令并将命令写入cmd,c#,process,cmd,C#,Process,Cmd,我正试图打开一个cmd.exe,并从多个文本框中写入它。但是除了cmd,我什么也看不到: System.Diagnostics.Process.Start("cmd", "perl "+ textBox5.Text + textBox4.Text + textBox6.Text + textBox7.Text + textBox8.Text + textBox9.Text); 您应该在参数的开头添加参数/c或/k 您需要使用选项/c启动cmd,并通过使用

我正试图打开一个
cmd.exe
,并从多个文本框中写入它。但是除了cmd,我什么也看不到:

System.Diagnostics.Process.Start("cmd", "perl "+ textBox5.Text + textBox4.Text + textBox6.Text + textBox7.Text + textBox8.Text + textBox9.Text);

您应该在参数的开头添加参数/c或/k


您需要使用选项
/c
启动
cmd
,并通过使用
cmd/c”perl…
这样的
传递下面的每个数据,或者您可以启动
perl
作为进程,并将其他所有内容作为参数传递

您可以找到有关参数的详细文档

因此,您必须将代码更改为

System.Diagnostics.Process.Start("cmd","/c \"perl "+ textBox5.Text + textBox4.Text + textBox6.Text + textBox7.Text + textBox8.Text + textBox9.Text + "\"");

此外:您可以通过不将
+
字符串
结合使用来提高代码的可读性和性能。如果要使用,可以将代码更改为以下代码:

StringBuilder arguments = new StringBuilder();
arguments.Append(textBox5.Text);
arguments.Append(textBox4.Text);
arguments.Append(textBox6.Text);
arguments.Append(textBox7.Text);
arguments.Append(textBox8.Text);
arguments.Append(textBox9.Text);

System.Diagnostics.Process.Start("perl", arguments.ToString());

我已经发布了一个答案,希望有帮助;-)尝试在
System.Diagnostics.Process.Start expamples
上进行谷歌搜索这里有很多这样的例子@waypass:如果我的答案对你有帮助,请给我一个向上投票的机会-thx。没有声誉yetA不加解释的向下投票总是很好的…:-(
StringBuilder arguments = new StringBuilder();
arguments.Append(textBox5.Text);
arguments.Append(textBox4.Text);
arguments.Append(textBox6.Text);
arguments.Append(textBox7.Text);
arguments.Append(textBox8.Text);
arguments.Append(textBox9.Text);

System.Diagnostics.Process.Start("perl", arguments.ToString());