创设进程并且等待进程结束

创建进程并且等待进程结束Processクラスを利用し、プロセスを作成、実行結果を取得する。ポイント1、WaitForExit() サブプロセス実行完

创建进程并且等待进程结束

Processクラスを利用し、プロセスを作成、実行結果を取得する。

ポイント1、WaitForExit() サブプロセス実行完了まで、親プロセスを止まらせる。

ポイント2、ExitCodeプロパティより、サブプロセスの実行結果を取得。

ポイント3、戻り値を付けられる Main で戻り値を返す。

?

using System;using System.Collections.Generic;using System.Text;using System.Diagnostics;namespace RmsUpdate{    class RmsUpdate    {        static int Main(string[] args)        {            string strBatPath = "setup.bat";            Process pro = new Process();            int exitCode = 0;            try            {                pro.StartInfo.UseShellExecute = true;                pro.StartInfo.FileName = strBatPath;                pro.StartInfo.CreateNoWindow = true;                pro.Start();                pro.WaitForExit();                exitCode = pro.ExitCode;            }            catch (Exception)            {                exitCode = 1;            }            finally            {                if (pro != null)                {                    pro.Close();                    pro.Dispose();                }            }            return exitCode;        }    }}
?