How to use C # process

Source: Internet
Author: User

public static string Executeaaptcommand (string appName, String command)
{
string result = String. Empty;
String error = String. Empty;
Try
{
using (Process process = new process ())
{
Process. Startinfo.filename = AppName; Sets the program name.
Process. startinfo.arguments = command; Set program parameters.
Process. Startinfo.useshellexecute = false;
Process. Startinfo.redirectstandardinput = true;
Process. Startinfo.redirectstandardoutput = true;
Process. Startinfo.redirectstandarderror = true;
Process. startinfo.standardoutputencoding = Encoding.UTF8; Set standard output encoding
Process. Startinfo.createnowindow = true; The window is not displayed.
Process. Start ();

result = process. Standardoutput.readtoend ();
Error = process. Standarderror.readtoend ();

Console.WriteLine ("Command:" + command + "\ r \ n" + result);

Process. WaitForExit ();

Process. Close ();
}
}
catch (Exception ex)
{
Throw ex;
}
return result;
}

The Windows System cmd command defaults to output cp936 encoding, or gb2312.

Process. startinfo.standardoutputencoding = Encoding.UTF8; This sentence, the code is set to Utf-8, to ensure that Chinese will not garbled.

"Aapt.exe d badging xxx.apk > xxx.txt" outputs the output to xxx.txt.

How to use C # process

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.