C # execute shell command

xiaoxiao2021-04-02  211

I just wrote such something. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; // added, using the process class, Create an independent process

Namespace WindowsApplication1 {public Partial Class Form1: form {public form1 () {initializationComponent ();

Private Void Form1_Load (Object Sender, Eventargs E) {// Instance A Process Class Process Process = New Process (); // Set Program Name Process.StartInfo.FileName = "cmd.exe"; // Close Shell Using Process .StartInfo.UseShellExecute = false; // redirecting the standard input, input, output error process.StartInfo.RedirectStandardInput = true; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; // set the window does not display process cmd .Startinfo.createnowindow = true; // Start process.Start (); // Enter command, exit process.standardinput.writeline ("ping 192.168.0.1"); //process.standardinput.writeline ("Netstat "); Process .Standardinput.writeline ("exit"); // Get results string strrst = process.standardoutput.readToEnd (); // Display result to richtextbox this.richtextBox1.text = strrst;}}}

转载请注明原文地址:https://www.9cbs.com/read-131447.html

New Post(0)