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; // 设定程序名称。
process.StartInfo.Arguments = command; // 设定程序参数。
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.StandardOutputEncoding = Encoding.UTF8; //设置标准输出编码
process.StartInfo.CreateNoWindow = true; // 不显示窗口。
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;
}
windows系统下 cmd 命令默认输出cp936编码,即gb2312.
process.StartInfo.StandardOutputEncoding = Encoding.UTF8; 这句,将编码设置成utf-8,保证中文不会乱码。
"aapt.exe d badging xxx.apk > xxx.txt" 将输出结果输出到xxx.txt中。