我在CMD中创建了一个运行命令。
var process = Process.Start("CMD.exe", "/c apktool d app.apk");
process.WaitForExit();
如何在不显示实际CMD窗口的情况下运行此命令?
答案 0 :(得分:7)
您可以将WindowsStyle-Property用于indicate whether the process is started in a window that is maximized, minimized, normal (neither maximized nor minimized), or not visible
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
<强>来源:强> 物业:MSDN Enumartion:MSDN
并将代码更改为此,因为您在初始化对象时启动了该过程,因此将无法识别属性(在启动过程后设置的属性)。
Process proc = new Process();
proc.StartInfo.FileName = "CMD.exe";
proc.StartInfo.Arguments = "/c apktool d app.apk";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.Start();
proc.WaitForExit();
答案 1 :(得分:5)
正如各种评论和答案中所指出的,您的计划存在一些问题。我试着在这里解决所有问题。
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "apktool";
//join the arguments with a space, this allows you to set "app.apk" to a variable
psi.Arguments = String.Join(" ", "d", "app.apk");
//leave it to the application, not the OS to launch the file
psi.UseShellExecute = false;
//choose to not create a window
psi.CreateNoWindow = true;
//set the window's style to 'hidden'
psi.WindowStyle = ProcessWindowStyle.Hidden;
var proc = new Process();
proc.StartInfo = psi;
proc.Start();
proc.WaitForExit();
主要问题:
cmd /c
答案 2 :(得分:1)
试试这个:
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.WaitForExit();
答案 3 :(得分:-1)
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.CreateNoWindow = true;
startInfo.UseShellExecute = false;
startInfo.FileName = "dcm2jpg.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;