-2

到目前爲止,我有這樣的:我想打電話從多個文本框的值,並創建一個命令行參數

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 
+0

什麼問題都具有創造這樣的程序嗎? – Servy

+0

我不知道如何調用該行中的textbox1 2或7的值 proc.StandardInput.WriteLine(「program.exe textbox7 --username = textbox1 --password = textbox2 --list」); –

+0

你如何將字符串連接在一起進行了哪些研究?你發現了什麼信息,它是如何解決你的問題的? – Servy

回答

0

請注意

  1. 你不需要調用的CMD.exe。您可以直接調用program.exe。
  2. 您不需要使用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(); 
+0

我會試試看,謝謝 –

+0

完美工作!但是我必須調用cmd作爲program.exe運行在commdo提示符下! 非常感謝! (y) –

+0

很高興我可以幫助@heppaappeh –

相關問題