예제 #1
2
 /// <summary>
 /// 生成FLV视频的缩略图
 /// </summary>
 /// <param name="vFileName">视频文件地址</param>
 /// <param name="FlvImgSize">宽和高参数,如:240*180</param>
 /// <returns></returns>
 public static string CatchImg(string vFileName, string FlvImgSize, string Second)
 {
     if (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(vFileName)))
         return "";
     try
     {
         string flv_img_p = vFileName.Substring(0, vFileName.Length - 4) + "_thumbs.jpg";
         string Command = " -i \"" + HttpContext.Current.Server.MapPath(vFileName) + "\" -y -f image2 -ss " + Second + " -t 0.1 -s " + FlvImgSize + " \"" + HttpContext.Current.Server.MapPath(flv_img_p) + "\"";
         System.Diagnostics.Process p = new System.Diagnostics.Process();
         p.StartInfo.FileName = @"ffmpeg.exe";
         p.StartInfo.Arguments = Command;
         p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
         p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/bin/tools/");
         //不创建进程窗口
         p.StartInfo.CreateNoWindow = true;
         p.Start();//启动线程
         p.WaitForExit();//等待完成
         p.Close();//关闭进程
         p.Dispose();//释放资源
         System.Threading.Thread.Sleep(4000);
         //注意:图片截取成功后,数据由内存缓存写到磁盘需要时间较长,大概在3,4秒甚至更长;
         if (System.IO.File.Exists(HttpContext.Current.Server.MapPath(flv_img_p)))
         {
             return flv_img_p;
         }
         return "";
     }
     catch
     {
         return "";
     }
 }
예제 #2
0
        //CheckEpubを実施、Output/Errorを表示する
        public void CheckEpub()
        {
            //EPUBチェック実施中パネルを表示する
            var checkingDlg = new EpubCheckingDialog();
            checkingDlg.Show();

            var p = new System.Diagnostics.Process();

            //実行ファイル
            p.StartInfo.FileName = javaPath;

            //引数
            var args = "-jar "
                        + "\""+ epubCheckPath + "\" "
                        +" \"" + epubPath + "\"";
            p.StartInfo.Arguments = args;

            //出力とエラーをストリームに書き込むようにする
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;

            //OutputDataReceivedとErrorDataReceivedイベントハンドラを追加
            p.OutputDataReceived += OutputDataReceived;
            p.ErrorDataReceived += ErrorDataReceived;

            p.StartInfo.RedirectStandardInput = false;
            p.StartInfo.CreateNoWindow = true;

            p.Start();

            p.BeginOutputReadLine();
            p.BeginErrorReadLine();

            p.WaitForExit();
            p.Close();

            var resultDlg = new EpubCheckResultDialog();

            //Outputをコピーする
            foreach (var output in outputLines)
            {
                resultDlg.outputTextBox.Text += (output + "\n");
            }

            //Errorをコピーする
            if (errorLines.Count> 1)
            {
                foreach (var error in errorLines)
                {
                    resultDlg.errorTextBox.Text += (error + "\n");
                }
            }
            else
            {
                resultDlg.errorTextBox.Text = "エラーはありませんでした。";
            }
            checkingDlg.Close();
            resultDlg.ShowDialog();
        }
예제 #3
0
        public static string Execute(string command)
        {
            var p = new System.Diagnostics.Process();

            //设定程序名

            p.StartInfo.FileName = "cmd.exe";

            //关闭Shell的使用

            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(command); //这里就可以输入你自己的命令
            var str= p.StandardOutput.ReadLine();
            p.Close();
            return str;
        }
예제 #4
0
        public static void GetScreenShot(string path,string filename)
        {
            //string result = "";
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = path + "\\adb.exe";
            //要执行的程序名称
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            //可能接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;
            //由调用程序获取输出信息
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = "shell /system/bin/screencap -p /sdcard/" + filename;
            //不显示程序窗口
            p.Start();

            //result += p.StandardOutput.ReadToEnd();
            //p.BeginOutputReadLine();
            p.WaitForExit();
            while (p.ExitCode != 0)
            {
                //result += p.StandardOutput.ReadToEnd();
                //Thread.Sleep(200);
            }
            p.Close();
            return;
        }
예제 #5
0
파일: Patcher.cs 프로젝트: jrfl/exeopt
        public static void ApplyPatch(FpuSegment seg)
        {
            Process p=new Process();
            p.StartInfo.FileName="nasm.exe";
            p.StartInfo.Arguments="out.txt";
            p.StartInfo.UseShellExecute=false;
            p.StartInfo.CreateNoWindow=true;
            p.Start();
            p.WaitForExit();
            p.Close();
            FileInfo fi=new FileInfo("out");
            if(fi.Length==0) throw new OptimizationException("Patcher: Code generator produced uncompilable code");
            ArrayList code=new ArrayList();
            for(int i=0;i<seg.Pre.Length;i++) {
                code.AddRange(HexToString(seg.Pre[i].code));
            }
            code.AddRange(Program.ReadFileBytes("out"));
            for(int i=0;i<seg.Post.Length;i++) {
                code.AddRange(HexToString(seg.Post[i].code));
            }
            if(code.Count>seg.End-seg.Start) throw new OptimizationException("Patcher: Patch to big to fit into code");

            /*if(Program.TestPatches) {
                TestPatch(seg); //TESTPATCH CALL
            }*/
            if(Program.Benchmark) {
                Benchmark(seg); //BENCHMARK CALL!!!!!!!!!!!!!!!!!!!!!!!! <---------------- OVER HERE
            }
            byte[] Code=new byte[seg.End-seg.Start];
            code.CopyTo(Code);
            for(int i=code.Count;i<(seg.End-seg.Start);i++) {
                Code[i]=144;    //Fill the rest of the code up with nop's
            }
            long a=(seg.End-seg.Start)-code.Count;
            if(a>255) {
                throw new OptimizationException("Patcher: Patch end address out of range of a short jump");
            } else if(a>2) {
                Code[code.Count]=235;
                Code[code.Count+1]=(byte)(a-2);
            }
            if(Program.Restrict) {
                if(PatchCount<Program.FirstPatch||PatchCount>Program.LastPatch) {
                    PatchCount++;
                    throw new OptimizationException("Patcher: Patch restricted");
                }
                PatchCount++;
            }
            #if emitpatch
            FileStream fs2=File.Create("emittedpatch.patch",4096);
            BinaryWriter bw=new BinaryWriter(fs2);
            bw.Write(seg.Start);
            bw.Write(Code.Length);
            bw.Write(Code,0,Code.Length);
            bw.Close();
            #endif
            FileStream fs=File.Open("code",FileMode.Open);
            fs.Position=seg.Start;
            fs.Write(Code,0,Code.Length);
            fs.Close();
        }
예제 #6
0
 /// <summary>
 /// 使用cmd环境执行命令,同步执行一句传入命令
 /// </summary>
 /// http://www.cnblogs.com/wucg/archive/2012/03/16/2399980.html
 /// <param name="workDir"></param>
 /// <param name="cmdStr"></param>
 public static void callCmdSync(string workDir, string cmdStr)
 {
     System.Diagnostics.Process p = new System.Diagnostics.Process();
     p.EnableRaisingEvents = false;
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.CreateNoWindow = false;//true
     p.StartInfo.RedirectStandardInput = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.FileName = "cmd.exe"; //fileName;
     p.StartInfo.WorkingDirectory = workDir;//@"E:\";
     //p.StartInfo.Arguments = args;//传入bat的参数
     p.StartInfo.LoadUserProfile = false;
     p.Start();
     //输出到命令行
     p.StandardInput.WriteLine(cmdStr);
     p.StandardInput.WriteLine("exit");
     //捕获不到类似 dirxxx的错误信息
     //string ret = p.StandardOutput.ReadToEnd(); //获取返回值
     //LogOutput.logConsoleNow(ret);
     /* 按行获取返回值 */
     string line = p.StandardOutput.ReadLine();//每次读取一行
     while (!p.StandardOutput.EndOfStream) {
         if (line != string.Empty) {
             LogOutput.logConsoleNow(line + " ");
         }
         line = p.StandardOutput.ReadLine();
     }
     p.WaitForExit();
     p.Close();
     LogOutput.logConsoleNow("--cmd over--");
 }
예제 #7
0
        public static string GetDevice(string path)
        {
            string result = "";
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = path + "\\adb.exe";
            //要执行的程序名称
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardInput = true;
            //可能接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;
            //由调用程序获取输出信息
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.Arguments = "devices";
            //不显示程序窗口
            p.Start();

            result += p.StandardOutput.ReadToEnd();
            //p.BeginOutputReadLine();
            p.WaitForExit();
            while (p.ExitCode != 0)
            {
                result += p.StandardOutput.ReadToEnd();
                Thread.Sleep(200);
            }
            p.Close();
            return result;
        }
예제 #8
0
        /// <summary>
        /// 読み取り開始
        /// </summary>
        public void Read()
        {
            Console.WriteLine("FelicaReader::Read() - start");
            //  プロセスオブジェクトを生成
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            //  実行ファイルを指定
            p.StartInfo.FileName = this.tagtool;
            //  シェルコマンドを無効に
            p.StartInfo.UseShellExecute = false;
            //  入力をリダイレクト
            p.StartInfo.RedirectStandardInput = true;
            //  出力をリダイレクト
            p.StartInfo.RedirectStandardOutput = true;
            //  OutputDataReceivedイベントハンドラを追加
            p.OutputDataReceived += OutputDataReceivedHandler;
            //  プロセスを実行
            p.Start();
            //  非同期で出力の読み取りを開始
            p.BeginOutputReadLine();
            //  入力を行う為のストリームライターとプロセスの標準入力をリンク
            System.IO.StreamWriter myStreamWriter = p.StandardInput;

            myStreamWriter.Close();
            p.WaitForExit();
            p.Close();
            Console.WriteLine("FelicaReader::Read() - end");
        }
예제 #9
0
        public static void Extract(string Archive, string Output)
        {
            string cmd = null, arg = null;
            System.Diagnostics.Process P = new System.Diagnostics.Process();

            if (OS.IsWindows)
            {
                cmd = "cmd.exe";
                arg = String.Format("/c .\\unpack.exe x -y -o\"{0}\" \"{1}\"", Output, Archive);
            }
            else
            {
                cmd = "bash";
                arg = String.Format("-c \"./unpack x \\\"{1}\\\" -so | tar xf - -C \\\"{0}\\\" && echo ONE ADDONS UPDATED!\"", Output, Archive);
            }

            P.StartInfo.FileName = cmd;
            P.StartInfo.Arguments = arg;
            P.StartInfo.WorkingDirectory = Globals.AppInfo.CurrentFolder;
            P.StartInfo.UseShellExecute = false;
            P.StartInfo.CreateNoWindow = true;

            P.Start();
            P.WaitForExit();
            P.Close();
        }
예제 #10
0
 private void btnManualusuario_Click(object sender, EventArgs e)
 {
     System.Diagnostics.Process proc = new System.Diagnostics.Process();
     proc.StartInfo.FileName = "C:/Users/Jessica/Desktop/proyecto1grupo1 unificado/proyecto1grupo1_Version4 admin&gestion&reportes unificados/proyecto1grupo1/bin/Debug/manualdeusuario.pdf";
     proc.Start();
     proc.Close();
 }
        /// <summary>
        /// Convert Html page at a given URL to a PDF file using open-source tool wkhtml2pdf
        /// </summary>
        public static bool CreateFromURL(string url, string outputFilePath, bool hideBackground = false, int margin = 10)
        {
            var p = new System.Diagnostics.Process();
            p.StartInfo.FileName = HttpContext.Current.Server.MapPath(@"~\wkhtmltopdf\wkhtmltopdf.exe");

            var switches = String.Format("--print-media-type --margin-top {0}mm --margin-bottom {0}mm --margin-right {0}mm --margin-left {0}mm --page-size Letter --redirect-delay 100", margin);
            if (hideBackground) switches += "--no-background ";

            p.StartInfo.Arguments = switches + " " + url + " " + outputFilePath;

            p.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
            p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(@"~\wkhtmltopdf\");

            p.Start();

            // read the output here...
            string output = p.StandardOutput.ReadToEnd();

            // ...then wait n milliseconds for exit (as after exit, it can't read the output)
            p.WaitForExit(60000);

            // read the exit code, close process
            int returnCode = p.ExitCode;
            p.Close();

            // if 0 or 2, it worked (not sure about other values, I want a better way to confirm this)
            return (returnCode == 0 || returnCode == 2);
        }
    private void setupPortForwarding(int port) {
      string adbCommand = string.Format("adb forward tcp:{0} tcp:{0}", port);
      System.Diagnostics.Process myProcess;

#if UNITY_EDITOR_WIN
      string cmd = @"/k " + adbCommand + " & exit";
      Debug.Log ("Executing: [" + cmd + "]");
      myProcess = new System.Diagnostics.Process();
      System.Diagnostics.ProcessStartInfo myProcessStartInfo =
        new System.Diagnostics.ProcessStartInfo("CMD.exe", cmd);
      myProcessStartInfo.UseShellExecute = false;
      myProcessStartInfo.RedirectStandardOutput = true;
      myProcessStartInfo.CreateNoWindow = true;
      myProcess.StartInfo = myProcessStartInfo;
      myProcess.Start();
#else
      Debug.LogFormat("Trying to launch adb: {0}", adbCommand);
      myProcess = System.Diagnostics.Process.Start("bash", string.Format("-l -c \"{0}\"",
                                                                         adbCommand));
#endif
      myProcess.WaitForExit();
      int exitCode = myProcess.ExitCode;
      myProcess.Close();
      if (exitCode == 0) {
        Debug.LogFormat("adb process succeeded (exit code 0).");
      } else {
        Debug.LogErrorFormat("adb process FAILED (exit code {0}). Check that the Android SDK " +
            "is installed and that the adb command is in your PATH environment variable.",
            exitCode);
      }
    }
        public String convert(string pdfdoc)
        {
            String command = "";
            try
            {
                String output = "";

                command = configManager.getConfig("cmd.conversion.splitpdffile");
                command = command.Replace("{path.pdf}", configManager.getConfig("path.pdf"));
                command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
                command = command.Replace("{pdffile}", pdfdoc);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow = true;
                //proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    proc.WaitForExit();
                    proc.Close();
                    return "[OK]";
                }
                else
                    return "[Error converting splitting PDF, please check your configuration]";
            }
            catch (Exception ex)
            {
                return "[" + ex.Message + "]";
            }
        }
예제 #14
0
 /// <summary>
 /// 视频格式转为Flv
 /// </summary>
 /// <param name="vFileName">原视频文件地址</param>
 /// <param name="ExportName">生成后的Flv文件地址</param>
 public bool ConvertFlv(string vFileName, string ExportName)
 {
     if ((!System.IO.File.Exists(ffmpegtool)) || (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(vFileName))))
     {
         return false;
     }
     vFileName = HttpContext.Current.Server.MapPath(vFileName);
     ExportName = HttpContext.Current.Server.MapPath(ExportName);
     string Command = " -i \"" + vFileName + "\" -y -ab 32 -ar 22050 -b 800000 -s  480*360 \"" + ExportName + "\""; //Flv格式     
     System.Diagnostics.Process p = new System.Diagnostics.Process();
     p.StartInfo.FileName = ffmpegtool;
     p.StartInfo.Arguments = Command;
     p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/tools/");
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardInput = true;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.CreateNoWindow = false;
     p.Start();
     p.BeginErrorReadLine();
     p.WaitForExit();
     p.Close();
     p.Dispose();
     return true;
 }
예제 #15
0
        private void playitems()
        {
            foreach (ListViewItem item in Playlist.Items)
            {
                // now spawn mplayer sessions for the playlist...
                string strCmdLine;
                strCmdLine = "-fs " + item.ImageKey;
                string originalName = item.Name;
                item.Name = item.Name + " [now playing]";

                System.Diagnostics.Process mplayerprocess;
                mplayerprocess = new System.Diagnostics.Process();

                //Do not receive an event when the process exits.
                mplayerprocess.EnableRaisingEvents = false;

                mplayerprocess = System.Diagnostics.Process.Start("mplayer.exe", strCmdLine);

                while (!mplayerprocess.HasExited)
                {
                    if (!PlaylistManager.play) break;
                    System.Threading.Thread.Sleep(10);
                }

                mplayerprocess.Close();

                item.Name = originalName;
            }
        }
예제 #16
0
        public void MovieMaking(String name,int rate,int dig)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            String currentDirectory = System.IO.Directory.GetCurrentDirectory();
            String imageSource = Images[0].Path;
            imageSource = imageSource.Substring(0, imageSource.Length - (4+dig));
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
            //出力を読み取れるようにする
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput = false;
            //ウィンドウを表示しないようにする
            p.StartInfo.CreateNoWindow = true;
            //コマンドラインを指定("/c"は実行後閉じるために必要)
            p.StartInfo.Arguments = @"/c cd " + currentDirectory + " &cores\\ffmpeg.exe -f image2 -r " + rate.ToString() + " -i " + imageSource + "%0" + dig.ToString() + "d.jpg -r " + rate.ToString() + " -an -vcodec libx264 -pix_fmt yuv420p " +name+ ".mp4";
            //起動
            p.Start();

            //出力を読み取る
            string results = p.StandardOutput.ReadToEnd();

            //プロセス終了まで待機する
            //WaitForExitはReadToEndの後である必要がある
            //(親プロセス、子プロセスでブロック防止のため)
            p.WaitForExit();
            p.Close();
            Mouse.OverrideCursor = null;
        }
예제 #17
0
파일: CompressFile.cs 프로젝트: LuoSven/EM
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pSource">要压缩的文件夹</param>
        /// <param name="pDestination">压缩后的rar完整名</param>
        public void CreateRar(string pSource, string pDestination)
        {
            try
            {
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = "Winrar.exe";
                proc.StartInfo.CreateNoWindow = true;
                proc.StartInfo.Arguments = " a -r -ep1 " + pDestination + " " + pSource;
                proc.Start();
                proc.WaitForExit();
                if (proc.HasExited)
                {
                    int iExitCode = proc.ExitCode;
                    if (iExitCode == 0)
                    {//压缩成功}
                    }
                    else
                    {
                    }
                }
                proc.Close();
            }
            catch (Exception ex)
            {

            }
        }
예제 #18
0
 /// <summary>
 /// PDF格式转为SWF
 /// </summary>
 /// <param name="pdfPath">PDF文件地址</param>
 /// <param name="swfPath">生成后的SWF文件地址</param>
 /// <param name="beginpage">转换开始页</param>
 /// <param name="endpage">转换结束页</param>
 private static bool PDF2SWF(string pdfPath, string swfPath, int beginpage, int endpage, int photoQuality)
 {
     string exe = HttpContext.Current.Server.MapPath("~/Bin/tools/pdf2swf-0.9.1.exe");
     pdfPath = HttpContext.Current.Server.MapPath(pdfPath);
     swfPath = HttpContext.Current.Server.MapPath(swfPath);
     if (!System.IO.File.Exists(exe) || !System.IO.File.Exists(pdfPath) || System.IO.File.Exists(swfPath))
     {
         return false;
     }
     StringBuilder sb = new StringBuilder();
     sb.Append(" \"" + pdfPath + "\"");
     sb.Append(" -o \"" + swfPath + "\"");
     sb.Append(" -s flashversion=9");
     if (endpage > GetPageCount(pdfPath)) endpage = GetPageCount(pdfPath);
     sb.Append(" -p " + "\"" + beginpage + "" + "-" + endpage + "\"");
     sb.Append(" -j " + photoQuality);
     string Command = sb.ToString();
     System.Diagnostics.Process p = new System.Diagnostics.Process();
     p.StartInfo.FileName = exe;
     p.StartInfo.Arguments = Command;
     p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.CreateNoWindow = false;
     p.Start();
     p.BeginErrorReadLine();
     p.WaitForExit();
     p.Close();
     p.Dispose();
     return true;
 }
예제 #19
0
 /// <summary>
 /// 文件加解密
 /// </summary>
 /// <param name="oFileName">原文件地址</param>
 /// <param name="EncodeOrDecode">加密或解密参数,如:-d、-f</param>
 /// <param name="Password">密码</param>
 /// <returns></returns>
 public static bool FileCrypt(string oFileName, string EncodeOrDecode, string Password)
 {
     string jpfile = HttpContext.Current.Server.MapPath("~/Bin/tools/jpfile.exe");
     if ((!System.IO.File.Exists(jpfile)) || (!System.IO.File.Exists(HttpContext.Current.Server.MapPath(oFileName))))
     {
         return false;
     }
     oFileName = HttpContext.Current.Server.MapPath(oFileName);
     string Command = EncodeOrDecode + " \"" + oFileName + "\" \"" + Password + "\"";
     System.Diagnostics.Process p = new System.Diagnostics.Process();
     p.StartInfo.FileName = jpfile;
     p.StartInfo.Arguments = Command;
     p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/Bin/");
     p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序 启动 线程
     //p.StartInfo.RedirectStandardInput = true;
     //p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,jpfile的所有输出信息,都为错误输出流,用 StandardOutput是捕获不到任何消息的...
     p.StartInfo.CreateNoWindow = false;//不创建进程窗口
     p.Start();//启动线程
     p.BeginErrorReadLine();//开始异步读取
     p.WaitForExit();//等待完成
     //p.StandardError.ReadToEnd();//开始同步读取
     p.Close();//关闭进程
     p.Dispose();//释放资源
     return true;
 }
예제 #20
0
 private void button2_Click(object sender, EventArgs e)
 {
     openFileDialog1.ShowDialog();
     System.Diagnostics.Process command = new System.Diagnostics.Process();
     command.StartInfo.FileName = @"C:\Program Files\Adobe\Reader 11.0\Reader\acrord32.exe";
     command.StartInfo.Arguments = openFileDialog1.FileName;
     command.Start();
     command.WaitForExit(31000);
     command.Close();
 }
예제 #21
0
 public void Aplay(string src)
 {
     System.Diagnostics.Process proc = new System.Diagnostics.Process();
     proc.EnableRaisingEvents = true;
     proc.StartInfo.FileName = "aplay";
     proc.StartInfo.Arguments = src;
     proc.Start();
     proc.WaitForExit ();
     proc.Close ();
 }
        public bool LoadFile()
        {
            bool curReturn = false;
            int delimPos = 0;
            String curTourDirectory = "";
            String curFileName = "IwwfHomologationDossier.txt";
            String curDestFileName = mySanctionNum + "HD.TXT";

            try {
                String curDeploymentDirectory = "";
                try {
                    //curDeploymentDirectory = ApplicationDeployment.CurrentDeployment.DataDirectory;
                    curDeploymentDirectory = Application.StartupPath;
                    if ( curDeploymentDirectory == null ) { curDeploymentDirectory = ""; }
                    if ( curDeploymentDirectory.Length < 1 ) {
                        curDeploymentDirectory = "C:\\Users\\AllenFamily\\Documents\\Visual Studio 2010\\Projects\\WaterskiScoringSystem\\WaterskiScoringSystem\\\bin\\Debug";
                    }
                } catch ( Exception ex ) {
                    if ( curDeploymentDirectory == null ) { curDeploymentDirectory = ""; }
                    if ( curDeploymentDirectory.Length < 1 ) {
                        curDeploymentDirectory = "C:\\Users\\AllenFamily\\Documents\\Visual Studio 2010\\Projects\\WaterskiScoringSystem\\WaterskiScoringSystem\\\bin\\Debug";
                    }
                }

                curTourDirectory = Properties.Settings.Default.ExportDirectory;
                if ( curTourDirectory == null ) { curTourDirectory = ""; }
                if ( curTourDirectory.Length > 1 ) {
                    if ( curTourDirectory.Substring( curTourDirectory.Length - 1 ) != "\\" ) {
                        curTourDirectory += "\\";
                    }
                    if (curDeploymentDirectory.Substring( curDeploymentDirectory.Length - 1 ) != "\\") {
                        curDeploymentDirectory += "\\";
                    }

                    //Declare and instantiate a new process component.
                    System.Diagnostics.Process curOSProcess = new System.Diagnostics.Process();

                    //Do not receive an event when the process exits.
                    curOSProcess.EnableRaisingEvents = true;

                    //The "/C" Tells Windows to Run The Command then Terminate
                    string curCmdLine;
                    curCmdLine = "/C copy \"" + curDeploymentDirectory + curFileName + "\" \"" + curTourDirectory + curDestFileName + "\" \n";

                    System.Diagnostics.Process.Start( "CMD.exe", curCmdLine );
                    curOSProcess.Close();
                    MessageBox.Show( "File " + curDeploymentDirectory + curFileName + "\n copied to \n" + curTourDirectory + curDestFileName );
                }
            } catch ( Exception ex ) {
                MessageBox.Show( "Error loading IwwfHomologation file to tournament directory " + "\n\nError: " + ex.Message );
            }
            return curReturn;

            return true;
        }
        /* C:\\Program Files (x86)\\wkhtmltopdf\\wkhtmltopdf.exe */
        /// <summary>
        /// Convert Html page at a given URL to a PDF file using open-source tool wkhtml2pdf
        ///   wkhtml2pdf can be found at: http://code.google.com/p/wkhtmltopdf/
        ///   Useful code used in the creation of this I love the good folk of StackOverflow!: http://stackoverflow.com/questions/1331926/calling-wkhtmltopdf-to-generate-pdf-from-html/1698839
        ///   An online manual can be found here: http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html
        ///   
        /// Ensure that the output folder specified is writeable by the ASP.NET process of IIS running on your server
        /// 
        /// This code requires that the Windows installer is installed on the relevant server / client.  This can either be found at:
        ///   http://code.google.com/p/wkhtmltopdf/downloads/list - download wkhtmltopdf-0.9.9-installer.exe
        /// </summary>
        /// <param name="pdfOutputLocation"></param>
        /// <param name="outputFilenamePrefix"></param>
        /// <param name="urls"></param>
        /// <param name="options"></param>
        /// <param name="pdfHtmlToPdfExePath"></param>
        /// <returns>the URL of the generated PDF</returns>
        public static string HtmlToPdf(string pdfOutputLocation, string outputFilenamePrefix, string[] urls,
            string[] options = null,
            string pdfHtmlToPdfExePath = "C:\\Program Files\\wkhtmltopdf\\wkhtmltopdf.exe")
        {
            string urlsSeparatedBySpaces = string.Empty;
            try
            {
                //Determine inputs
                if ((urls == null) || (urls.Length == 0))
                    throw new Exception("No input URLs provided for HtmlToPdf");
                else
                    urlsSeparatedBySpaces = String.Join(" ", urls); //Concatenate URLs

                string outputFolder = pdfOutputLocation;
                string outputFilename = outputFilenamePrefix + "_" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss-fff") + ".PDF"; // assemble destination PDF file name

                var p = new System.Diagnostics.Process()
                {
                    StartInfo =
                    {
                        FileName = pdfHtmlToPdfExePath,
                        Arguments = ((options == null) ? "" : String.Join(" ", options)) + " " + urlsSeparatedBySpaces + " " + outputFilename,
                        UseShellExecute = false, // needs to be false in order to redirect output
                        RedirectStandardOutput = true,
                        RedirectStandardError = true,
                        RedirectStandardInput = true, // redirect all 3, as it should be all 3 or none
                        WorkingDirectory = outputFolder
                    }
                };

                p.Start();

                // read the output here...
                var output = p.StandardOutput.ReadToEnd();
                var errorOutput = p.StandardError.ReadToEnd();

                // ...then wait n milliseconds for exit (as after exit, it can't read the output)
                p.WaitForExit(60000);

                // read the exit code, close process
                int returnCode = p.ExitCode;
                p.Close();

                // if 0 or 2, it worked so return path of pdf
                if ((returnCode == 0) || (returnCode == 2))
                    return outputFolder + outputFilename;
                else
                    throw new Exception(errorOutput);
            }
            catch (Exception exc)
            {
                throw new Exception("Problem generating PDF from HTML, URLs: " + urlsSeparatedBySpaces + ", outputFilename: " + outputFilenamePrefix, exc);
            }
        }
예제 #24
0
        /// <summary> 
        /// 递归列举出指定目录的所有文件         /// </summary> 
        public static void ListFiles(FileSystemInfo info, string _rex)
        {
            if (!info.Exists) return;
            DirectoryInfo dir = info as DirectoryInfo;                 //不是目录
            if (dir == null) return;
            string _filePath = string.Empty;
            Dictionary<DateTime, string> _fs = new Dictionary<DateTime, string>();
            FileSystemInfo[] files = dir.GetFileSystemInfos(_rex + "_*.rar");
            for (int i = 0; i < files.Length; i++)
            {
                FileInfo f = files[i] as FileInfo;                     //是文件
                if (f != null)
                {
                    //string _fn = f.Name;
                    //Regex r = new Regex("epis_.*_");
                    //string _t = r.Replace(_fn, "").Replace(".rar", "");

                    DateTime _dt = f.CreationTimeUtc;
                    _fs.Add(_dt, f.FullName);
                }
            }
            Dictionary<DateTime, string> dic1 = _fs.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);
            _filePath = dic1[dic1.Keys.Max()];
            FileInfo file = new FileInfo(_filePath);
            if (file != null)
            {
                AddFileSecurity(file.FullName, "Everyone", FileSystemRights.FullControl, AccessControlType.Allow);
                Config.DatabaseFile = file.FullName;

                System.Diagnostics.Process p = new System.Diagnostics.Process();

                try
                {
                    System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo();
                    startinfo.FileName = @"WinRAR.exe";//需要启动的程序名
                    string rarPath = file.Directory.FullName;
                    startinfo.Arguments = string.Format("x -p0x00000000025203a0 {0} {1}", file.FullName, rarPath);//启动参数
                                                                                                                  //设置命令参数
                                                                                                                  //startinfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;  //隐藏 WinRAR 窗口
                    p.StartInfo = startinfo;
                    p.Start();//启动
                    p.WaitForExit(); //无限期等待进程 winrar.exe 退出
                }
                catch (Exception ex) { throw ex; }
                finally
                {
                    p.Dispose();
                    p.Close();
                }
            }
        }
예제 #25
0
 private void btn_run_Click(object sender, EventArgs e)
 {
     System.Diagnostics.Process p = new System.Diagnostics.Process();
     p.StartInfo.FileName = txt_javaPath.Text;
     p.StartInfo.Arguments = txt_argumentos.Text;
     p.StartInfo.UseShellExecute = false;
     p.StartInfo.RedirectStandardOutput = true;
     p.StartInfo.RedirectStandardError = true;
     p.StartInfo.CreateNoWindow = true;
     p.Start();
     p.WaitForExit();
     txt_salida.Text = p.StandardOutput.ReadToEnd();
     txt_salida.Text += p.StandardError.ReadToEnd();
     p.Close();
 }
예제 #26
0
 private void sidbutton_Click(object sender, RoutedEventArgs e)
 {
     var process = new System.Diagnostics.Process();
     //process.StartInfo.WorkingDirectory = "c:\\";
     process.StartInfo.UseShellExecute = false;
     process.StartInfo.FileName = "PsGetsid.exe";
     process.StartInfo.Arguments = UrsNametxtb.Text;
     process.StartInfo.CreateNoWindow = true;
     process.StartInfo.RedirectStandardInput = true;
     process.StartInfo.RedirectStandardOutput = true;
     process.StartInfo.RedirectStandardError = true;
     process.Start();
     string output = process.StandardOutput.ReadToEnd();
     process.Close();
     Outbox.Text = output;
 }
예제 #27
0
 protected virtual bool RunCommand( string szCmd, string szArgs, int wait )
 {
     if( szCmd == null ) return false;
     System.Diagnostics.Process myproc = new System.Diagnostics.Process( );
     myproc.EnableRaisingEvents = false;
     myproc.StartInfo.FileName = szCmd;
     myproc.StartInfo.Arguments = szArgs;
     if( myproc.Start( )  )
     {
         //Using WaitForExit( ) allows for the host program
         //to wait for the command its executing before it continues
         if( wait == 1 ) myproc.WaitForExit( );
         else myproc.Close( );
         return true;
     }
     else return false;
 }
예제 #28
0
        public void SpeakAsync(string text)
        {
            if (text == null)
                return;

            text = Regex.Replace(text, @"\bPreArm\b", "Pre Arm", RegexOptions.IgnoreCase);
            text = Regex.Replace(text, @"\bdist\b", "distance", RegexOptions.IgnoreCase);
            text = Regex.Replace(text, @"\bNAV\b", "Navigation", RegexOptions.IgnoreCase);
            text = Regex.Replace(text, @"\b([0-9]+)m\b", "$1 meters", RegexOptions.IgnoreCase);
            text = Regex.Replace(text, @"\b([0-9]+)ft\b", "$1 feet", RegexOptions.IgnoreCase);

            if (MONO)
            {
                try
                {
                    //if (_speechlinux == null)
                    {
                        _state = SynthesizerState.Speaking;
                        _speechlinux = new System.Diagnostics.Process();
                        _speechlinux.StartInfo.RedirectStandardInput = true;
                        _speechlinux.StartInfo.UseShellExecute = false;
                        _speechlinux.StartInfo.FileName = "festival";
                        _speechlinux.Start();
                        _speechlinux.Exited += new EventHandler(_speechlinux_Exited);

                        log.Info("TTS: start " + _speechlinux.StartTime);

                    }

                    _state = SynthesizerState.Speaking;
                    _speechlinux.StandardInput.WriteLine("(SayText \"" + text + "\")");
                    _speechlinux.StandardInput.WriteLine("(quit)");

                    _speechlinux.Close();
                }
                catch { } // ignore errors

                _state = SynthesizerState.Ready;
            }
            else
            {
                _speechwindows.SpeakAsync(text);
            }

            log.Info("TTS: say " + text);
        }
예제 #29
0
        protected ActionResult Jpg(string url)
        {
            string path = Server.MapPath("~/Wkhtml/");
            string file_name = path + "Temp\\" + Common.uniqueStr() + ".jpg";
            string para = Common.genPara();
            if (para != string.Empty)
            {
                url += "?" + para;
            }

            var p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "\"" + path + "wkhtmltoimage.exe\"";

            string switches = "--no-stop-slow-scripts ";
            switches += "--javascript-delay 1000 ";
            switches += "--quality 100 ";

            p.StartInfo.Arguments = switches + " \"" + Common.getDomain() + url + "\" \"" + file_name + "\"";

            p.StartInfo.UseShellExecute = false; // needs to be false in order to redirect output
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true; // redirect all 3, as it should be all 3 or none
            p.StartInfo.WorkingDirectory = path;

            p.Start();

            // ...then wait n milliseconds for exit (as after exit, it can't read the output)
            p.WaitForExit(60000);

            // read the exit code, close process
            int returnCode = p.ExitCode;
            p.Close();

            // if 0 or 2, it worked (not sure about other values, I want a better way to confirm this)
            if (returnCode == 0 || returnCode == 2)
            {
                var pdf = this.File(System.IO.File.ReadAllBytes(file_name), "image/jpeg");
                System.IO.File.Delete(file_name);
                return pdf;
            }
            else
            {
                return Content("建立 JPG 失敗");
            }
        }
예제 #30
0
        public static bool CmdLog(string log) {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName = "cmd.exe";
            p.StartInfo.UseShellExecute = false;    //是否使用操作系统shell启动
            p.StartInfo.RedirectStandardInput = true;//接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;//由调用程序获取输出信息
            p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
            p.StartInfo.CreateNoWindow = true;//不显示程序窗口
            p.Start();//启动程序

            //向cmd窗口发送输入信息
            p.StandardInput.WriteLine("echo " + log + ">> LogData.txt&exit" + "&exit");

            p.StandardInput.AutoFlush = true;
            p.WaitForExit();//等待程序执行完退出进程
            p.Close();

            return false;
        }
예제 #31
0
        internal static int AddProjectsToSolution(string solutionPath, string[] projects)
        {
            var proc         = new System.Diagnostics.Process();
            var projectPaths = projects.Select((name) => $"\"{Path.Combine(Path.GetDirectoryName(solutionPath), name).ToString()}\"");

            try
            {
                proc.StartInfo.FileName               = @"dotnet";
                proc.StartInfo.Arguments              = $"sln \"{solutionPath}\" add {string.Join(" ", projectPaths)}";
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.Start();
                string outPut = proc.StandardOutput.ReadToEnd();
                proc.WaitForExit();
                var exitCode = proc.ExitCode;
                return(exitCode);
            }
            finally
            {
                proc.Close();
            }
        }
예제 #32
0
        public static void exeCommand(string str)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName               = "cmd.exe";
            p.StartInfo.UseShellExecute        = false; //是否使用操作系统shell启动
            p.StartInfo.RedirectStandardInput  = true;  //接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;  //由调用程序获取输出信息
            p.StartInfo.RedirectStandardError  = true;  //重定向标准错误输出
            p.StartInfo.CreateNoWindow         = true;  //不显示程序窗口
            p.Start();                                  //启动程序

            //向cmd窗口发送输入信息
            p.StandardInput.WriteLine(str + "&exit");

            p.StandardInput.AutoFlush = true;
            //p.StandardInput.WriteLine("exit");
            //向标准输入写入要执行的命令。这里使用&是批处理命令的符号,表示前面一个命令不管是否执行成功都执行后面(exit)命令,如果不执行exit命令,后面调用ReadToEnd()方法会假死
            //同类的符号还有&&和||前者表示必须前一个命令执行成功才会执行后面的命令,后者表示必须前一个命令执行失败才会执行后面的命令

            p.WaitForExit();//等待程序执行完退出进程
            p.Close();
        }
예제 #33
0
        public void StartServer()
        {
            try
            {
                p = new System.Diagnostics.Process();
                //入力できるようにする
                p.StartInfo.UseShellExecute       = false;
                p.StartInfo.RedirectStandardInput = true;

                //非同期で出力を読み取れるようにする
                p.StartInfo.RedirectStandardOutput = true;
                p.OutputDataReceived += p_OutputDataReceived;

                p.StartInfo.FileName       = "cmd.exe";
                p.StartInfo.CreateNoWindow = true;

                //起動
                p.Start();

                //非同期で出力の読み取りを開始
                p.BeginOutputReadLine();

                sw = p.StandardInput;
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine("cd /d c:");
                    sw.WriteLine("cd {0}", ini["Minecraft", "ServerDir"]);
                    sw.WriteLine(ini["Minecraft", "CmdLine"]);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                p.WaitForExit();
                p.Close();
            }
        }
예제 #34
0
 private void btnTestVoice_Click(object sender, EventArgs e)
 {
     System.Diagnostics.Process proc = new System.Diagnostics.Process
     {
         StartInfo = new System.Diagnostics.ProcessStartInfo
         {
             FileName  = PictureFunctions.Globals.AppSettings.pathToESpeak,
             Arguments = cmbParams.Text + " \"" + txtTestText.Text + "\"",
             //Arguments = "-v female3 \"" + textBox1.Text + "\"",
             UseShellExecute        = false,
             RedirectStandardOutput = true,
             CreateNoWindow         = true
         }
     };
     proc.Start();
     while (!proc.StandardOutput.EndOfStream)
     {
         string line = proc.StandardOutput.ReadLine();
         // just loop until the process ends
     }
     proc.Close();
 }
예제 #35
0
        static void split(string[] files)
        {
            Console.WriteLine("");
            Console.WriteLine("正在拆分:");

            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName               = "cmd.exe";
            p.StartInfo.UseShellExecute        = false; //是否使用操作系统shell启动
            p.StartInfo.RedirectStandardInput  = true;  //接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;  //由调用程序获取输出信息
            p.StartInfo.RedirectStandardError  = true;  //重定向标准错误输出
            p.StartInfo.CreateNoWindow         = true;  //不显示程序窗口
            p.Start();                                  //启动程序

            //向cmd窗口发送输入信息
            for (int i = 1; i < files.Count(); i++)
            {
                if (File.Exists(@files[i]))
                {
                    Console.WriteLine(Path.GetFileName(@files[i]));
                    string str = "pdftk.exe \"" + files[i] + "\" burst ";
                    //Console.WriteLine(str);
                    p.StandardInput.WriteLine("cd \"" + Path.GetDirectoryName(@files[i]) + "\"");
                    p.StandardInput.WriteLine("mkdir \"" + Path.GetFileNameWithoutExtension(@files[i]) + "\"");
                    p.StandardInput.WriteLine("cd \"" + Path.GetFileNameWithoutExtension(@files[i]) + "\"");
                    p.StandardInput.WriteLine(str);
                }
            }
            p.StandardInput.WriteLine("exit");

            p.StandardInput.AutoFlush = true;

            string output = p.StandardOutput.ReadToEnd();

            p.WaitForExit();
            p.Close();

            Console.WriteLine(output);
        }
예제 #36
0
        /// <summary>
        /// 获取CMD执行结果
        /// </summary>
        /// <param name="command">命令</param>
        /// <returns></returns>
        public static string execCMD(string command)
        {
            System.Diagnostics.Process pro = new System.Diagnostics.Process();
            pro.StartInfo.FileName               = "cmd.exe";
            pro.StartInfo.UseShellExecute        = false;
            pro.StartInfo.RedirectStandardError  = true;
            pro.StartInfo.RedirectStandardInput  = true;
            pro.StartInfo.RedirectStandardOutput = true;
            pro.StartInfo.CreateNoWindow         = true;
            //pro.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            pro.Start();
            pro.StandardInput.WriteLine(command);
            pro.StandardInput.WriteLine("exit");
            pro.StandardInput.AutoFlush = true;
            //获取cmd窗口的输出信息
            string output = pro.StandardOutput.ReadToEnd();

            pro.WaitForExit();//等待程序执行完退出进程
            pro.Close();
            output = output.Substring(output.IndexOf(command));
            return(output.Substring(0, output.Length - 1));
        }
예제 #37
0
        //[MenuItem("Tools/编译Hotfix")]
        public static void BuildHotfix()
        {
            System.Diagnostics.Process process = new System.Diagnostics.Process();
            string unityDir = System.Environment.GetEnvironmentVariable("Unity");

            if (string.IsNullOrEmpty(unityDir))
            {
                Log.Error("没有设置Unity环境变量!");
                return;
            }
            process.StartInfo.FileName               = $@"{unityDir}\Editor\Data\MonoBleedingEdge\bin\mono.exe";
            process.StartInfo.Arguments              = $@"{unityDir}\Editor\Data\MonoBleedingEdge\lib\mono\xbuild\14.0\bin\xbuild.exe .\Hotfix\Unity.Hotfix.csproj";
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.WorkingDirectory       = @".\";
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.Start();
            string info = process.StandardOutput.ReadToEnd();

            process.Close();
            Log.Info(info);
        }
예제 #38
0
        private static string ExecuteCmd(string cmd)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName               = ADB_FILE_NAME;
            p.StartInfo.Arguments              = cmd;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.CreateNoWindow         = true;

            p.Start();

            p.StandardInput.AutoFlush = true;

            string output = p.StandardOutput.ReadToEnd();

            p.WaitForExit();
            p.Close();

            return(output);
        }
예제 #39
0
        static public void CompilerDll(string _filename, string _args)
        {
            try
            {
                System.Diagnostics.Process tprocess = new System.Diagnostics.Process();
                tprocess.StartInfo.FileName  = _filename;
                tprocess.StartInfo.Arguments = _args;

                tprocess.StartInfo.RedirectStandardOutput = true;
                tprocess.BeginOutputReadLine();
                tprocess.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(SortOutputHandler);
                tprocess.Start();

                tprocess.WaitForExit();
                tprocess.CancelOutputRead();
                tprocess.Close();
            }
            catch (System.Exception ex)
            {
                DLog.LogError(ex.Message);
            }
        }
예제 #40
0
        public static string theDirtyCMD(string cmd)
        {
            System.Diagnostics.Process p = new System.Diagnostics.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();

            p.StandardInput.WriteLine(str + " & exit");

            p.StandardInput.AutoFlush = true;

            var output = p.StandardOutput.ReadToEnd();

            p.WaitForExit();//等待程序执行完退出进程
            p.Close();

            return(output);
        }
예제 #41
0
        public static Dictionary <string, object> MakeQR(string content, string imagePath, string imageName, bool show)
        {
            string filePath;

            if (!Directory.Exists(imagePath))
            {
                try
                {
                    Directory.CreateDirectory(imagePath);
                    filePath = Path.Combine(imagePath, imageName);
                }
                catch { throw new Exception("请检查imagePath是否为合法的路径格式!"); }
            }
            else
            {
                filePath = Path.Combine(imagePath, imageName);
                QRCodeGenerator       qrGenerator = new QRCodeGenerator();
                QRCodeData            qrCodeData  = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.Q);
                QRCode                qrCode      = new QRCode(qrCodeData);
                System.Drawing.Bitmap qrCodeImage = qrCode.GetGraphic(20);
                qrCodeImage.Save(filePath);
                qrCodeImage.Dispose();

                if (show)
                {
                    System.Diagnostics.Process process = new System.Diagnostics.Process();
                    process.StartInfo.FileName        = filePath;
                    process.StartInfo.Arguments       = "rundll32.exe C:\\WINDOWS\\system32\\shimgvw.dll,ImageView_Fullscreen";
                    process.StartInfo.UseShellExecute = true;
                    process.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                    process.Start();
                    process.Close();
                }
            }
            return(new Dictionary <string, object>
            {
                { "ImagePath", filePath }
            });
        }
예제 #42
0
        private bool deleteTempFile(String inFileName)
        {
            try {
                //Declare and instantiate a new process component.
                System.Diagnostics.Process curOSProcess = new System.Diagnostics.Process();

                //Do not receive an event when the process exits.
                curOSProcess.EnableRaisingEvents = true;

                //The "/C" Tells Windows to Run The Command then Terminate
                string curCmdLine;
                curCmdLine = "/C DEL \"" + inFileName + "\" \n";
                System.Diagnostics.Process.Start("CMD.exe", curCmdLine);
                curOSProcess.Close();
                return(true);
            } catch (Exception ex) {
                MessageBox.Show("Error: Deleting temp file " + inFileName
                                + "\n\nException: " + ex.Message
                                );
                return(false);
            }
        }
예제 #43
0
파일: Helper.cs 프로젝트: m916423330/WPF-
        /// <summary>
        /// 启动外部应用程序
        /// </summary>
        /// <param name="appName">应用程序路径名称</param>
        /// <param name="arguments">启动参数</param>
        /// <param name="style">进程窗口模式</param>
        /// <returns></returns>
        public static bool StartApp(string appName, string arguments, System.Diagnostics.ProcessWindowStyle style)
        {
            bool result = false;

            using (System.Diagnostics.Process p = new System.Diagnostics.Process())
            {
                p.StartInfo.FileName    = appName;//exe,bat and so on
                p.StartInfo.WindowStyle = style;
                p.StartInfo.Arguments   = arguments;
                try
                {
                    p.Start();
                    p.WaitForExit();
                    p.Close();
                    result = true;
                }
                catch
                {
                }
            }
            return(result);
        }
예제 #44
0
        public static string[] Cmd(string exeQuery)
        {
            System.Diagnostics.Process p = new System.Diagnostics.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();

            p.StandardInput.WriteLine(exeQuery + "&exit");
            p.StandardInput.AutoFlush = true;

            string output = p.StandardOutput.ReadToEnd();

            var x = new List <string>();

            while (p.StandardOutput.Peek() > -1)
            {
                x.Add(p.StandardOutput.ReadLine());
            }

            while (p.StandardError.Peek() > -1)
            {
                x.Add(p.StandardError.ReadLine());

                string errMsg = MsgHandle(x.Last() + "    Internal Command = [" + exeQuery + "]", exeQuery);
                RCLogMessage.Instance().Log(errMsg);
            }

            p.WaitForExit();

            p.Close();

            //return output;
            return(x.ToArray());
        }
예제 #45
0
        public static string GetMimeType(string Filename)
        {
//			string exec = "file ;
            System.Diagnostics.Process process = new System.Diagnostics.Process();
//			process.StartInfo.FileName = exec;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.FileName  = "/usr/bin/file";
            process.StartInfo.Arguments = "--mime-type -F ';' " + Filename;
            process.Start();

            string output = string.Empty;

//			try
//			{
            output = process.StandardOutput.ReadToEnd();
//			}
//			catch
//			{
//			}

            process.WaitForExit();
            process.Close();

//			output = output.TrimEnd ("\n".ToCharArray ());
//			output ="./media/avatars/test(18).jpg; image/jpeg";
            string[] split = output.Split(";".ToCharArray());


            return(split[1].Trim());



//			string exec = "chmod "+ Chmod.ToString() +" \""+ Filename +"\"";
//			System.Diagnostics.Process process = new System.Diagnostics.Process();
//			process.StartInfo.FileName = exec;
//			process.Start();
        }
예제 #46
0
        static public void Follow_INPUTtxt(int k)
        {
            // code image =>video
            string[] Count_Mp3 = File.ReadAllLines(@"C:\RACC\Data\Video" + k + @"\Input.txt", Encoding.UTF8);
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
            string Ghep_File = "";

            for (int i = 0; i < Count_Mp3.Length; i++)
            {
                if (i == Count_Mp3.Length - 1)
                {
                    Ghep_File += "\"" + i + ".mp3" + "\"";
                }
                else
                {
                    Ghep_File += "\"" + i + ".mp3" + "\"" + "+ ";
                }
            }


            ////    Ghép âm thanh đã tải về
            {
                startInfo.WorkingDirectory = @"C:\RACC\Data\Video" + k + @"\Voice"; // tạo đường dẫn để thực hiện lệnh arguments
                startInfo.FileName         = "cmd.exe";                             // khởi tạo cmd
                process.StartInfo          = startInfo;                             //
                startInfo.Arguments        = "/C copy /b " + Ghep_File + @" C:\RACC\Data\Video" + k + @"\Image\TotalMusic.mp3";
                // System.Windows.Forms.MessageBox.Show(startInfo.Arguments);
                process.Start();
                process.Close();

                //  mg("Ghép xong TotalMusic");
            }

            // done ghép âm thanh đã tải về
            Thread.Sleep(2000);
        }
예제 #47
0
        public void SpeakAsync(string text)
        {
            text = text.Replace("PreArm", "Pre Arm");

            if (MONO)
            {
                try
                {
                    //if (_speechlinux == null)
                    {
                        _state       = SynthesizerState.Speaking;
                        _speechlinux = new System.Diagnostics.Process();
                        _speechlinux.StartInfo.RedirectStandardInput = true;
                        _speechlinux.StartInfo.UseShellExecute       = false;
                        _speechlinux.StartInfo.FileName = "festival";
                        _speechlinux.Start();
                        _speechlinux.Exited += new EventHandler(_speechlinux_Exited);

                        log.Info("TTS: start " + _speechlinux.StartTime);
                    }

                    _state = SynthesizerState.Speaking;
                    _speechlinux.StandardInput.WriteLine("(SayText \"" + text + "\")");
                    _speechlinux.StandardInput.WriteLine("(quit)");

                    _speechlinux.Close();
                }
                catch { } // ignore errors

                _state = SynthesizerState.Ready;
            }
            else
            {
                _speechwindows.SpeakAsync(text);
            }

            log.Info("TTS: say " + text);
        }
예제 #48
0
        /* Read the measure export CSV stream
         * INPUTS: Measure Export Path; Properties File Path; Properties File Name
         * OUTPUT: Datatable containing the parsed CSV Dataset
         */
        public static DataTable ReadStream(string measureExportPath, string propertiesFilePath, string propertiesFile)
        {
            System.Diagnostics.Process p = new System.Diagnostics.Process();

            p.StartInfo.WorkingDirectory = measureExportPath;

            if (GlobalVariables.exportVersion == "x64")
            {
                p.StartInfo.FileName = "\"" + measureExportPath + @"\exportMeasure_amd64.exe" + "\""; //64-bit version
            }
            else
            {
                p.StartInfo.FileName = "\"" + measureExportPath + @"\exportMeasure.exe" + "\""; //32-bit version
            }
            p.StartInfo.Arguments = "-p " + "\"" + propertiesFilePath + "\\" + propertiesFile + "\"";
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardError  = true;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.CreateNoWindow         = true;
            p.Start();

            StreamReader myStreamReader = p.StandardOutput;
            StreamReader myErrorReader  = p.StandardError;

            DataTable myDataTable = CsvParser.Parse(myStreamReader);

            // READ ERROR STREAM
            string error = myErrorReader.ReadToEnd();

            if (error != "")
            {
                myDataTable.Columns.Add("Error", typeof(string));
                myDataTable.Rows.Add(error);
            }

            p.Close();
            return(myDataTable);
        }
예제 #49
0
        //***********************************************************************************************************************************************
        public static string MSbuild()
        {
            System.IO.StreamWriter sw = new System.IO.StreamWriter(
                @"now.txt",
                false);
            //TextBox1.Textの内容を書き込む
            sw.Write(Hensu.ProjectPath);
            //閉じる
            sw.Close();
            //Processオブジェクトを作成
            System.Diagnostics.Process p = new System.Diagnostics.Process();

            //ComSpec(cmd.exe)のパスを取得して、FileNameプロパティに指定
            p.StartInfo.FileName = System.Environment.GetEnvironmentVariable("ComSpec");
            //出力を読み取れるようにする
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.RedirectStandardInput  = false;
            //ウィンドウを表示しないようにする
            p.StartInfo.CreateNoWindow = true;
            //コマンドラインを指定("/c"は実行後閉じるために必要)
            p.StartInfo.Arguments = @"cd /d" + Hensu.ProjectPath + @"\build" + @"&& C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe /clp:ErrorsOnly";

            //起動
            p.Start();

            //出力を読み取る
            string results = p.StandardOutput.ReadToEnd();

            //プロセス終了まで待機する
            //WaitForExitはReadToEndの後である必要がある
            //(親プロセス、子プロセスでブロック防止のため)
            p.WaitForExit();
            p.Close();

            //出力された結果を表示
            return(results);
        }
        private string excuteCmd(string cmd)
        {
            Console.WriteLine("excuteCmd" + cmd);
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            p.StartInfo.FileName               = "cmd.exe"; //调用命令提示符
            p.StartInfo.UseShellExecute        = false;     //是否使用操作系统shell启动
            p.StartInfo.RedirectStandardInput  = true;      //接受来自调用程序的输入信息
            p.StartInfo.RedirectStandardOutput = true;      //由调用程序获取输出信息
            p.StartInfo.RedirectStandardError  = true;      //重定向标准错误输出
            p.StartInfo.CreateNoWindow         = true;      //不显示程序窗口
            p.Start();                                      //启动程序

            //向cmd窗口发送输入信息
            p.StandardInput.WriteLine(cmd + "&exit");

            p.StandardInput.AutoFlush = true;
            //p.StandardInput.WriteLine("exit");
            //向标准输入写入要执行的命令。这里使用&是批处理命令的符号,表示前面一个命令不管是否执行成功都执行后面(exit)命令,如果不执行exit命令,后面调用ReadToEnd()方法会假死
            //同类的符号还有&&和||前者表示必须前一个命令执行成功才会执行后面的命令,后者表示必须前一个命令执行失败才会执行后面的命令

            //获取cmd窗口的输出信息
            string output = p.StandardOutput.ReadToEnd();

            //Console.WriteLine(output);

            //StreamReader reader = p.StandardOutput;
            //string line = reader.ReadLine();
            //while (!reader.EndOfStream)
            //{
            //    str += line + "  ";
            //    line = reader.ReadLine();
            //}

            p.WaitForExit();//等待程序执行完退出进程
            p.Close();
            //Console.WriteLine(output);
            return(output);
        }
예제 #51
0
        //Ejecuta el comando de UnoEE para importar los datos.
        private static void ExecuteImpoDatos(Company company, string ts, string reference)
        {
            String exeIMpodatos = "";

            try { exeIMpodatos = (new WmsTypes()).GetCompanyOption(company, "IMPODATOS").ToString(); }
            catch {}

            if (string.IsNullOrEmpty(exeIMpodatos))
            {
                throw new Exception("Variable de Configuración de IMPODATOS no definida.");
            }


            string username   = company.ErpConnection.UserName;
            string passwd     = company.ErpConnection.Password;
            string connection = company.ErpConnection.Domain;

            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.EnableRaisingEvents = false;

            if (!File.Exists(exeIMpodatos))
            {
                throw new Exception("Archivo " + exeIMpodatos + " no existe.");
            }

            exeIMpodatos            = exeIMpodatos.Replace("\\\\", "\\");
            proc.StartInfo.FileName = "\"" + exeIMpodatos + "\"";


            //Console.Write(proc.StartInfo.FileName);
            //Console.Write(" 1," + connection + "," + username + "," + passwd + "," + company + "," + ts + "," + reference + ",0");

            proc.StartInfo.Arguments      = "1," + connection + "," + username + "," + passwd + "," + company.ErpCode + "," + ts + "," + reference + ",0";
            proc.StartInfo.CreateNoWindow = true;
            proc.Start();
            proc.WaitForExit();
            proc.Close();
        }
예제 #52
0
        public String convert(string pdfdoc)
        {
            String command = "";

            try
            {
                String output = "";


                command = configManager.getConfig("cmd.conversion.splitpdffile");
                command = command.Replace("{path.pdf}", configManager.getConfig("path.pdf"));
                command = command.Replace("{path.swf}", configManager.getConfig("path.swf"));
                command = command.Replace("{pdffile}", pdfdoc);

                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName        = command.Substring(0, command.IndexOf(".exe") + 5);
                proc.StartInfo.UseShellExecute = false;
                proc.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                proc.StartInfo.CreateNoWindow  = true;
                //proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.Arguments = command.Substring(command.IndexOf(".exe") + 5);

                if (proc.Start())
                {
                    proc.WaitForExit();
                    proc.Close();
                    return("[OK]");
                }
                else
                {
                    return("[Error converting splitting PDF, please check your configuration]");
                }
            }
            catch (Exception ex)
            {
                return("[" + ex.Message + "]");
            }
        }
예제 #53
0
        private int getDeviceInfo()
        {
            int ret = -1;

            try
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.UseShellExecute        = false;
                p.StartInfo.CreateNoWindow         = true;
                p.StartInfo.FileName               = "cmd.exe";
                p.StartInfo.Arguments              = "/c adb shell getprop ro.product.model";
                p.StartInfo.RedirectStandardError  = true;
                p.StartInfo.RedirectStandardInput  = true;
                p.StartInfo.RedirectStandardOutput = true;

                p.Start();

                string outtr = p.StandardOutput.ReadToEnd();
                //MessageBox.Show(outtr);
                if ("" == outtr)
                {
                    devceinfo.Text = "no device";
                }
                else
                {
                    devceinfo.Text = outtr;
                    ret            = 0;
                }

                p.Close();
            }
            catch (Exception)
            {
                throw;
            }

            return(ret);
        }
예제 #54
0
        private static void exportSetThread(object obj)
        {
            string[] args = (string[])obj;
            if (args == null || args.Length < 3)
            {
                System.Windows.Forms.MessageBox.Show(Language.LanguageHelper.GetMsg(LMSG.exportMseImagesErr));
                return;
            }
            string mse_path = args[0];
            string setfile  = args[1];
            string path     = args[2];

            if (string.IsNullOrEmpty(mse_path) || string.IsNullOrEmpty(setfile))
            {
                System.Windows.Forms.MessageBox.Show(Language.LanguageHelper.GetMsg(LMSG.exportMseImagesErr));
                return;
            }
            else
            {
                string cmd = " --export " + setfile.Replace("\\\\", "\\").Replace("\\", "/") + " {card.gamecode}.png";
                mseProcess = new   System.Diagnostics.Process();
                mseProcess.StartInfo.FileName         = mse_path;
                mseProcess.StartInfo.Arguments        = cmd;
                mseProcess.StartInfo.WorkingDirectory = path;
                mseProcess.EnableRaisingEvents        = true;
                MyPath.CreateDir(path);
                try{
                    mseProcess.Start();
                    //等待结束,需要把当前方法放到线程里面
                    mseProcess.WaitForExit();
                    mseProcess.Exited += new EventHandler(exitHandler);
                    mseProcess.Close();
                    mseProcess = null;
                    System.Windows.Forms.MessageBox.Show(Language.LanguageHelper.GetMsg(LMSG.exportMseImages));
                }catch {
                }
            }
        }
예제 #55
0
        public void KillLink()
        {
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();//创建进程对象
            System.Diagnostics.ProcessStartInfo startinfo = new System.Diagnostics.ProcessStartInfo
            {
                FileName               = "cmd.exe",
                Arguments              = "/c" + @"Net Use /delete * /yes",
                UseShellExecute        = false,
                RedirectStandardInput  = false,
                RedirectStandardOutput = true,
                CreateNoWindow         = true
            };//创建进程时使用的一组值,如下面的属性
            //以下是隐藏cmd窗口的方法
            process.StartInfo = startinfo;

            if (process.Start())        //开始进程
            {
                process.WaitForExit();
                string output = process.StandardOutput.ReadToEnd();//读取进程的输出
                Console.WriteLine(output);
                process.Close();
            }
        }
        private string GetTemperature()
        {
            var si = new System.Diagnostics.Process
            {
                StartInfo =
                {
                    WorkingDirectory       = "/",
                    UseShellExecute        = false,
                    FileName               = "cat",
                    Arguments              = " /sys/bus/w1/devices/" + deviceId + "/w1_slave",
                    CreateNoWindow         = true,
                    RedirectStandardInput  = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true
                }
            };

            si.Start();
            string output = si.StandardOutput.ReadToEnd();

            si.Close();
            return(output);
        }
예제 #57
0
파일: Form1.cs 프로젝트: wlh1998/bitsepair
        public static void RunCmd(string cmd, out string output) //命令行调用函数
        {
            cmd = cmd.Trim().TrimEnd('&') + "&exit";             //说明:不管命令是否成功均执行exit命令,否则当调用ReadToEnd()方法时,会处于假死状态
            using (System.Diagnostics.Process p = new System.Diagnostics.Process())
            {
                p.StartInfo.FileName               = CmdPath;
                p.StartInfo.UseShellExecute        = false; //是否使用操作系统shell启动
                p.StartInfo.RedirectStandardInput  = true;  //接受来自调用程序的输入信息
                p.StartInfo.RedirectStandardOutput = true;  //由调用程序获取输出信息
                p.StartInfo.RedirectStandardError  = true;  //重定向标准错误输出
                p.StartInfo.CreateNoWindow         = true;  //不显示程序窗口
                p.Start();                                  //启动程序

                //向cmd窗口写入命令
                p.StandardInput.WriteLine(cmd);
                p.StandardInput.AutoFlush = true;

                //获取cmd窗口的输出信息
                output = p.StandardOutput.ReadToEnd();
                p.WaitForExit();//等待程序执行完退出进程
                p.Close();
            }
        }
예제 #58
0
        private static string StartLocal(string args)
        {
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            string cwd           = System.IO.Directory.GetCurrentDirectory();
            string webSrvBinPath = System.IO.Path.Combine(cwd, "websrv.exe");

            startInfo.FileName  = webSrvBinPath;
            startInfo.Arguments = args;
            Logger.LogWriteLine($"Start local web server for test: {startInfo.FileName} {startInfo.Arguments}");
            startInfo.UseShellExecute        = false;
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            process.StartInfo = startInfo;
            process.Start();
            string output    = process.StandardOutput.ReadToEnd();
            string errOutput = process.StandardError.ReadToEnd();

            process.WaitForExit();
            process.Close();
            Logger.LogWriteLine($"Local web server returns: {output}\n{errOutput}");
            return(output);
        }
예제 #59
0
        private void OuvrirFichier(string fichier)
        {
            try
            {
                // Instance de la classe Process
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                // Nom du fichier dont l'extension est connue du shell à ouvrir

                proc.StartInfo.FileName = fichier; //filename+ext;
                // Démarrage du processus. 
                // Notepad, si il est associé aux fichiers .txt,
                // sera lancé et ouvrira le fichier monfichier.txt

                proc.Start();
                // On libère les ressources dont on a plus besoin.
                proc.Close(); // Attention Close ne met pas fin au processus.
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
예제 #60
0
 /// <summary>
 /// Run a shell command.
 /// </summary>
 /// <param name="fileName">File name for the executable.</param>
 /// <param name="arguments">Command line arguments, space delimited.</param>
 /// <param name="output">Filled out with the result as printed to stdout.</param>
 /// <param name="error">Filled out with the result as printed to stderr.</param>
 public static void RunCommand(string fileName, string arguments, out string output, out string error)
 {
     using (var process = new System.Diagnostics.Process()) {
         var startInfo = new System.Diagnostics.ProcessStartInfo(fileName, arguments);
         startInfo.UseShellExecute        = false;
         startInfo.RedirectStandardError  = true;
         startInfo.RedirectStandardOutput = true;
         startInfo.CreateNoWindow         = true;
         process.StartInfo = startInfo;
         var outputBuilder = new StringBuilder();
         var errorBuilder  = new StringBuilder();
         process.OutputDataReceived += (sender, ef) => outputBuilder.AppendLine(ef.Data);
         process.ErrorDataReceived  += (sender, ef) => errorBuilder.AppendLine(ef.Data);
         process.Start();
         process.BeginOutputReadLine();
         process.BeginErrorReadLine();
         process.WaitForExit();
         process.Close();
         // Trims the output strings to make comparison easier.
         output = outputBuilder.ToString().Trim();
         error  = errorBuilder.ToString().Trim();
     }
 }