Run the command by calling Cmd in the code.

Source: Internet
Author: User

Private static void merge command (string strIp)
{

Process p = new Process ();

// Set the program name
P. StartInfo. FileName = "cmd.exe ";

// Close Shell usage

P. StartInfo. UseShellExecute = false;

// Redirect standard input

P. StartInfo. RedirectStandardInput = true;

// Redirect standard output

P. StartInfo. RedirectStandardOutput = true;

// Redirect error output

P. StartInfo. RedirectStandardError = true;

// Set not to display the window

P. StartInfo. CreateNoWindow = true;


// String pingrst;

P. Start ();

P. StandardInput. WriteLine (strIp );

P. StandardInput. WriteLine ("exit ");

String strRst = p. StandardOutput. ReadToEnd ();

// If (strRst. IndexOf ("(0% loss )")! =-1)

// Pingrst = "connection ";

// Else if (strRst. IndexOf ("Destination host unreachable .")! =-1)

// Pingrst = "unable to reach the target host ";

// Else if (strRst. IndexOf ("Request timed out .")! =-1)

// Pingrst = "timeout ";

// Else if (strRst. IndexOf ("Unknown host ")! =-1)

// Pingrst = "unable to Resolve Host ";

// Else

// Pingrst = strRst;

P. Close ();

// Return pingrst;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.