• 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();

  • 相关阅读:
    AtCoder Grand Contest 015 题解
    AtCoder Grand Contest 014 题解
    AtCoder Grand Contest 013 题解
    AtCoder Grand Contest 012 题解
    AtCoder Grand Contest 011 题解
    AtCoder Grand Contest 010 题解
    AtCoder Grand Contest 009 题解
    NOIP2017 Day2 题解
    博客园主题备份
    多项式全家桶
  • 原文地址:https://www.cnblogs.com/qc-id-01/p/8309411.html
Copyright © 2020-2023  润新知