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