Wednesday, August 13, 2014

C# start run external process program

        private void startSQL(string datadir)
        {
            ProcessStartInfo sqlprocessinfo = new ProcessStartInfo()
            {
                CreateNoWindow = true,
                UseShellExecute = false,
                WindowStyle = ProcessWindowStyle.Hidden,
                FileName = "bin\\mysqld.exe",
                Arguments = "--defaults-file=\"" + datadir + "-my.ini\" --datadir=\"" + datadir + "\""
            };

            try
            {
                Process sqlprocess = Process.Start(sqlprocessinfo);

                if (sqlprocess.HasExited)
                {
                    MessageBox.Show("Start MySQL failed.");
                }
                else
                {

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
        }

No comments: