public
static
void
Dex2Jar(
string
dexPath)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string cmd = Application.StartupPath;
cmd = @"cd /d " + cmd;
p.StandardInput.WriteLine(cmd);
cmd = "/"" + Application.StartupPath + "//"+ "dex2jar.bat" + "/" " + "/"" + dexPath + "classes.dex" + "/"";
if ((Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6))
{
cmd = Application.StartupPath + "//" + "dex2jar.bat" + " " + dexPath + "classes.dex";
}
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");

//string strOutput = null;
//strOutput = p.StandardOutput.ReadToEnd();
//Console.WriteLine(strOutput);
p.WaitForExit();
p.Close();
}
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe ";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
string cmd = Application.StartupPath;
cmd = @"cd /d " + cmd;
p.StandardInput.WriteLine(cmd);
cmd = "/"" + Application.StartupPath + "//"+ "dex2jar.bat" + "/" " + "/"" + dexPath + "classes.dex" + "/"";
if ((Environment.OSVersion.Platform == PlatformID.Win32NT) && (Environment.OSVersion.Version.Major >= 6))
{
cmd = Application.StartupPath + "//" + "dex2jar.bat" + " " + dexPath + "classes.dex";
}
p.StandardInput.WriteLine(cmd);
p.StandardInput.WriteLine("exit");
//string strOutput = null;
//strOutput = p.StandardOutput.ReadToEnd();
//Console.WriteLine(strOutput);
p.WaitForExit();
p.Close();
}
本文介绍了一种在C#中通过调用CMD来执行批处理文件的方法。该方法利用了Process类来启动CMD,并通过重定向标准输入、输出和错误来实现与批处理的交互。此外,还针对不同Windows版本进行了适配。


4184

被折叠的 条评论
为什么被折叠?



