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

opening and writing commands to a cmd from text box

我正在尝试打开 cmd.exe 并从多个文本框中写入内容。但是除了 cmd:

我什么也看不到
System.Diagnostics.Process.Start("cmd", "perl "+ textBox5.Text + textBox4.Text + textBox6.Text + textBox7.Text + textBox8.Text + textBox9.Text);

您应该必须将参数 /c 或 /k 添加到参数的开头

http://ss64.com/nt/cmd.html

您需要使用选项 /c 启动 cmd 并使用 " 传递每个后续数据,例如 cmd /c "perl ... 或者您可以直接启动 perl作为进程并将其他所有内容作为参数传递。

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

因此您必须将代码更改为

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

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

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

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