Exemple #1
0
 private void OutputDataReceived(object sender, DataReceivedEventArgs e)
 {
     if (!string.IsNullOrEmpty(e.Data))
     {
         string str = "[" + DateTime.Now.ToString() + "]    " + e.Data;
         DirFileHelper.WriteFile(logName, str);
     }
 }
Exemple #2
0
        public CmdHelper()
        {
            string dir = Environment.CurrentDirectory + "\\cmdLog\\";

            if (!dir.EndsWith("\\"))
            {
                dir = dir + "\\";
            }
            logName = DirFileHelper.CreateDirectory(dir) + DateTime.Now.ToString("yyyyMMddhhmmssfffff") + ".log";
            proc    = new Process();
        }
Exemple #3
0
        public CmdHelper(string logPath)
        {
            if (logPath.EndsWith("\\"))
            {
                logName = DirFileHelper.CreateDirectory(logPath) + DateTime.Now.ToString("yyyyMMddhhmmssfffff") + ".log";
            }
            else
            {
                logName = DirFileHelper.CreateDirectory(logPath) + "\\" + DateTime.Now.ToString("yyyyMMddhhmmssfffff") + ".log";
            }

            proc = new Process();
        }
Exemple #4
0
        public void Execute(string cmd, out string msg)
        {
            msg = "";
            proc.StartInfo.CreateNoWindow         = true;
            proc.StartInfo.FileName               = "cmd.exe";
            proc.StartInfo.UseShellExecute        = false;
            proc.StartInfo.RedirectStandardInput  = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError  = true;
            proc.Start();

            if (!string.IsNullOrEmpty(cmd))
            {
                proc.StandardInput.WriteLine(cmd.TrimEnd('&') + "&exit");
                proc.StandardInput.AutoFlush = true;
            }
            msg = proc.StandardOutput.ReadToEnd();

            proc.WaitForExit();
            proc.Close();

            DirFileHelper.WriteFile(logName, msg + "\n end");
        }