zoukankan      html  css  js  c++  java
  • Process使用

         public static string RunCmd(string cmd)
           {
               cmd = cmd.Trim().TrimEnd('&') + "&exit";
               string output = "";
               using (Process p = new Process())
               {
                   p.StartInfo.FileName = CmdPath;
                   p.StartInfo.UseShellExecute = false;       
                   p.StartInfo.RedirectStandardInput = true;  
                   p.StartInfo.RedirectStandardOutput = true;  
                   p.StartInfo.RedirectStandardError = true;  
                   p.StartInfo.CreateNoWindow = true;         
                   p.Start();
    
                 
                   p.StandardInput.WriteLine(cmd);
                   p.StandardInput.AutoFlush = true;
    
                 
                   output = p.StandardOutput.ReadToEnd();
                   p.WaitForExit();
                   p.Close();
               }
    
               string txt = output;
               return txt;
           }
     #region cmd命令调用
    
            public void StartCmdEvent(string c, HashListItem item)
            {
                Process p = new Process();
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.WorkingDirectory = Path.GetDirectoryName(ExePath);
                psi.FileName = ExePath;
                psi.Arguments = c;
                psi.CreateNoWindow = true;
                psi.UseShellExecute = false;
                psi.RedirectStandardOutput = true;
                psi.RedirectStandardError = true;
                p.OutputDataReceived += P_OutputDataReceived;
                p.EnableRaisingEvents = true;                      // 启用Exited事件  
                p.Exited += new EventHandler(CmdProcess_Exited);   // 注册进程失败事件  
                p.StartInfo = psi;
                item.WorkStatus = HashListItem.Status.Running;
                p.Start();
                p.BeginOutputReadLine();
                p.BeginErrorReadLine();
            }
    
    //退出
    private void CmdProcess_Exited(object sender, EventArgs e) { Process p = sender as Process; }

    //输出 private void P_OutputDataReceived(object sender, DataReceivedEventArgs e) { Process p = sender as Process; } #endregion

    ProcessStartInfo psi = new ProcessStartInfo();
                        psi.FileName = hashcatFile;
                     
                        string hash = radioButton1.Checked ? textBox1.Text : HashfileTextbox.Text;
                        string ss = " -m " + hashType + " -a " + attackMode + " -i --increment-min " + BruteforceMinUpDown.Value.ToString() + " --increment-max " + BruteforceMaxUpDown.Value.ToString() + " -o " + hashcatLoc + "cracked/" + timestamp + ".cracked " + hash;
                        psi.Arguments = " -m " + hashType +" -a " + attackMode +" -i --increment-min " + BruteforceMinUpDown.Value.ToString() +" --increment-max " + BruteforceMaxUpDown.Value.ToString() +" -o " + hashcatLoc +"cracked/" + timestamp +".cracked " + hash;
                        p.StartInfo = psi;
                        p.StartInfo.UseShellExecute = false;
                        p.StartInfo.RedirectStandardOutput = true;
                        p.StartInfo.RedirectStandardInput = true;
                        p.StartInfo.CreateNoWindow = true;
                        p.Start();
                        StreamWriter inputWriter = p.StandardInput;
                        Invoker.SetText(metroLabel6, "No speed data available...");
                        Invoker.SetText(metroLabel7, "");
                        while (!p.StandardOutput.EndOfStream)
                        {
                            string standard_output = p.StandardOutput.ReadLine();

                            if (standard_output.StartsWith("Speed"))
                            {
                                Invoker.SetText(metroLabel6,"Speed:" + Core.StringBetween(":"," (", standard_output));
                            }
                            else if (standard_output.StartsWith("Guess.Mask"))
                            {
                                Invoker.SetText(metroLabel7,"Cracking length:" + Core.StringBetween("[","]", standard_output));
                            }
                        }

                        p.WaitForExit();

  • 相关阅读:
    「NOI2018」 你的名字
    「刷题笔记」杂题
    关于~
    「刷题笔记」网络流
    「考试」联赛模拟40-45,晚间小测4-9
    「考试」联赛模拟36-39,noip晚间小测2-3
    「刷题笔记」莫队
    「考试」CSP-S 2020
    「考试」noip模拟9,11,13
    「刷题笔记」概率与期望
  • 原文地址:https://www.cnblogs.com/qc-id-01/p/8309411.html
Copyright © 2011-2022 走看看