我正在尝试从多个文本框调用值并创建命令行参数
I am trying to call values from multiple textboxes and create a command line argument
到目前为止我有这个:
ProcessStartInfo psi = new ProcessStartInfo("cmd");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
psi.WorkingDirectory = @"C:\";
var proc = Process.Start(psi);
string username = textBox1.Text;
string password = textBox2.Text; //not sure about these 3 lines is correct?
string urladdress = textBox7.Text;
proc.StandardInput
.WriteLine("program.exe URLHERE --username=****** --password=****** --list");
proc.StandardInput.WriteLine("exit");
string s = proc.StandardOutput.ReadToEnd();
richTextBox2.Text = s;
我的问题是让它像这样创建命令行:
program.exe https://website-iam-trying-to-reach.now --username=myusername --password=mypassword --list
请注意
- 您不需要致电 CMD.exe。可以直接调用program.exe
- 您不需要使用 StandardInput.WriteLine() 来传递参数。
您可以按如下方式传递参数:
string username = textBox1.Text;
string password = textBox2.Text;
string urladdress = textBox7.Text;
//Give full path here for program.exe
ProcessStartInfo psi = new ProcessStartInfo("program.exe");
//Pass arguments here
psi.Arguments = "program.exe " + urladdress + " --username=" + username + " --password=" + password + " --list";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = false;
psi.WorkingDirectory = @"C:\";
var proc = Process.Start(psi);
//You might want to use this line for the window to not exit immediately
proc.WaitForExit();
string s = proc.StandardOutput.ReadToEnd();
richTextBox2.Text = s;
proc.Close();
proc.Dispose();
到目前为止我有这个:
ProcessStartInfo psi = new ProcessStartInfo("cmd");
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
psi.WorkingDirectory = @"C:\";
var proc = Process.Start(psi);
string username = textBox1.Text;
string password = textBox2.Text; //not sure about these 3 lines is correct?
string urladdress = textBox7.Text;
proc.StandardInput
.WriteLine("program.exe URLHERE --username=****** --password=****** --list");
proc.StandardInput.WriteLine("exit");
string s = proc.StandardOutput.ReadToEnd();
richTextBox2.Text = s;
我的问题是让它像这样创建命令行:
program.exe https://website-iam-trying-to-reach.now --username=myusername --password=mypassword --list
请注意
- 您不需要致电 CMD.exe。可以直接调用program.exe
- 您不需要使用 StandardInput.WriteLine() 来传递参数。
您可以按如下方式传递参数:
string username = textBox1.Text;
string password = textBox2.Text;
string urladdress = textBox7.Text;
//Give full path here for program.exe
ProcessStartInfo psi = new ProcessStartInfo("program.exe");
//Pass arguments here
psi.Arguments = "program.exe " + urladdress + " --username=" + username + " --password=" + password + " --list";
psi.UseShellExecute = false;
psi.RedirectStandardOutput = true;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = false;
psi.WorkingDirectory = @"C:\";
var proc = Process.Start(psi);
//You might want to use this line for the window to not exit immediately
proc.WaitForExit();
string s = proc.StandardOutput.ReadToEnd();
richTextBox2.Text = s;
proc.Close();
proc.Dispose();