2016-02-14 19 views
-1

我想在c#中調用特殊命令行的gui。如何製作一個調用命令行C#的gui?

using System.Diagnostics; 
Process test = new Process(); 
test.StartInfo.FileName = "start apps.lp asd-3 chmod -2";  test.StartInfo.UseShellExecute = false; 
test.StartInfo.Arguments = "/all"; 
test.StartInfo.RedirectStandardOutput = true; 
test.Start(); 
textBox1.Text = test.StandardOutput.ReadToEnd(); 

,我得到的是錯誤:

的win32異常是未處理的

system.componentmodel.win32exception在System.dll中發生

+0

我試圖讓3個按鍵eatch一個電話就像一個命令顏色a –

回答

0

解決長期搜索後發現的。 ..超過2周的搜索...我找到了正確的解決方案。

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using System.Diagnostics; 
using System.IO; 

namespace WindowsFormsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      ProcessStartInfo psi = new ProcessStartInfo("net", "help"); 
      psi.UseShellExecute = false; 
      psi.RedirectStandardOutput = true; 
      psi.CreateNoWindow = false; 
      var proc = Process.Start(psi); 

      string s = proc.StandardOutput.ReadToEnd(); 

      textBox1.Text = s; 

     } 

     private void button2_Click(object sender, EventArgs e) 
     { 
      ProcessStartInfo psi = new ProcessStartInfo("cmd"); 
      psi.UseShellExecute = false; 
      psi.RedirectStandardOutput = true; 
      psi.CreateNoWindow = true; 
      psi.RedirectStandardInput = true; 
      var proc = Process.Start(psi); 

      proc.StandardInput.WriteLine(@"dir /w); 
      proc.StandardInput.WriteLine("exit"); 
      string s = proc.StandardOutput.ReadToEnd(); 

      textBox1.Text = s; 
     } 

     private void textBox1_TextChanged(object sender, EventArgs e) 
     { 

     } 
    } 
} 

我希望這會幫助需要的人。

但我仍然有同樣的問題!帶/ s :(爲什麼?!? 我想做一個DIR/s的完蛋了。 請幫助

我最好的問候。

+0

要問一個新問題,請使用頁面頂部的「Ask Question」按鈕。如果有幫助提供上下文,可以鏈接到此問題。 –