-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

完璧に働いた!しかし私はprogram.exeがcommdoプロンプトで実行されているのでcmdを呼び出さなければなりません! ありがとうございます! (y) –

+0

喜んで私は@heppaappehを助けることができる –

関連する問題