Beispiel #1
0
        /// 実行ボタンクリック時の動作
        public void Execute()
        {
            global::System.Diagnostics.ProcessStartInfo psInfo = new global::System.Diagnostics.ProcessStartInfo();
            psInfo.FileName         = this.FileName;
            psInfo.WorkingDirectory = this.WorkingDirectory;
            psInfo.Arguments        = this.Arguments;

            psInfo.CreateNoWindow         = true;
            psInfo.UseShellExecute        = false;
            psInfo.RedirectStandardInput  = true;
            psInfo.RedirectStandardOutput = true;
            psInfo.RedirectStandardError  = true;

            // Process p = Process.Start(psInfo);
            p                     = new global::System.Diagnostics.Process();
            p.StartInfo           = psInfo;
            p.OutputDataReceived += p_OutputDataReceived;
            p.ErrorDataReceived  += p_ErrorDataReceived;

            // プロセスの実行
            p.Start();

            // 標準入力への書き込み
            //if (InputString.Length > 0)
            p_WriteInputData(InputString);

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

            // 終わるまでまつ
            p.WaitForExit();
            this.ExitCode       = p.ExitCode;
            this.StandardOutput = standardOutputStringBuilder.ToString();
        }
Beispiel #2
0
        static void ShellExecCmdLine(IntPtr hInstance, IntPtr hwnd, string command, string startDir, global::System.Diagnostics.ProcessWindowStyle nShow, ShellExecCmdLineFlags dwSeclFlags)
        {
            string cmd  = command;
            string args = null;

            if (UrlIs(command, URLIS_URL))
            {
                cmd = command;
            }
            else
            {
                if (global::System.Environment.OSVersion.Version.Major >= 6)
                {
                    EvaluateSystemAndUserCommandLine(cmd, startDir, out cmd, out args, dwSeclFlags);
                }
                else
                {
                    EvaluateUserCommandLine(cmd, startDir, out cmd, out args);
                }
            }

            if (!UrlIs(cmd, URLIS_URL) &&
                (
                    (dwSeclFlags & ShellExecCmdLineFlags.SECL_USEFULLPATHDIR) == ShellExecCmdLineFlags.SECL_USEFULLPATHDIR ||
                    startDir == null ||
                    startDir.Length == 0))
            {
                string dir = QualifyWorkingDir(cmd);
                if (dir != null)
                {
                    startDir = dir;
                }
            }

            global::System.Diagnostics.ProcessStartInfo startInfo = new global::System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute         = true;
            startInfo.Arguments               = args;
            startInfo.FileName                = cmd;
            startInfo.WindowStyle             = global::System.Diagnostics.ProcessWindowStyle.Normal;
            startInfo.ErrorDialog             = (dwSeclFlags | ShellExecCmdLineFlags.SECL_NO_UI) == 0;
            startInfo.ErrorDialogParentHandle = hwnd;

            try
            {
                global::System.Diagnostics.Process.Start(startInfo);
            }
            catch (Exception e)
            {
                if (!startInfo.ErrorDialog)
                {
                    throw e;
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 使用Window系统文件浏览器打开文件
        /// </summary>
        /// <param name="filePath"> </param>
        public static void ShowExplorerWindow(string filePath)
        {
            global::System.Diagnostics.ProcessStartInfo info = new global::System.Diagnostics.ProcessStartInfo("Explorer.exe");
            //路径采用双斜杠,否则找不到目录
            string target = filePath.Replace("/", "\\");

            if (!global::System.IO.File.Exists(target))
            {
                return;
            }
            info.Arguments = "/select," + target;
            global::System.Diagnostics.Process.Start(info);
        }
Beispiel #4
0
        static void ShellExecCmdLine(IntPtr hInstance, IntPtr hwnd, string command, string startDir, global::System.Diagnostics.ProcessWindowStyle nShow, ShellExecCmdLineFlags dwSeclFlags)
        {
            string cmd = command;
            string args = null;
            if (UrlIs(command, URLIS_URL))
                cmd = command;
            else
            {
                if (global::System.Environment.OSVersion.Version.Major >= 6)
                    EvaluateSystemAndUserCommandLine(cmd, startDir, out cmd, out args, dwSeclFlags);
                else
                    EvaluateUserCommandLine(cmd, startDir, out cmd, out args);
            }

            if (!UrlIs(cmd, URLIS_URL)
                && (
                    (dwSeclFlags & ShellExecCmdLineFlags.SECL_USEFULLPATHDIR) == ShellExecCmdLineFlags.SECL_USEFULLPATHDIR
                    || startDir == null
                    || startDir.Length == 0))
            {
                string dir = QualifyWorkingDir(cmd);
                if (dir != null)
                    startDir = dir;
            }

            if (UserSettingStorage.Instance.LeaveCmdOpen && File.Exists(cmd))
            {
                bool needsCommandLine;

                try
                {

                    var peHeaderReader = new PeHeaderReader(cmd);

                    if (peHeaderReader.Is32BitHeader)
                        needsCommandLine = peHeaderReader.OptionalHeader32.Subsystem == 3; // IMAGE_SUBSYSTEM_WINDOWS_CUI == 3
                    else
                        needsCommandLine = peHeaderReader.OptionalHeader64.Subsystem == 3;
                }

                catch (Exception)
                {
                    // Error reading the headers. We will try to run the command the standard way.
                    needsCommandLine = false;
                }

                if (needsCommandLine)
                {
                    string cmdExe;
                    string dummy;
                    EvaluateSystemAndUserCommandLine("cmd.exe", startDir, out cmdExe, out dummy, dwSeclFlags);

                    // check whether user typed >cmd, because we don't want to create 2 nested shells
                    if (cmdExe != cmd)
                    {
                        args = string.Format("/k {0} {1}", cmd, args);
                        cmd = cmdExe;
                    }
                }
            }

            global::System.Diagnostics.ProcessStartInfo startInfo = new global::System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.Arguments = args;
            startInfo.FileName = cmd;
            startInfo.WindowStyle = global::System.Diagnostics.ProcessWindowStyle.Normal;
            startInfo.ErrorDialog = (dwSeclFlags | ShellExecCmdLineFlags.SECL_NO_UI) == 0;
            startInfo.ErrorDialogParentHandle = hwnd;

            try
            {
                global::System.Diagnostics.Process.Start(startInfo);
            }
            catch (Exception e)
            {
                if (!startInfo.ErrorDialog)
                    throw e;
            }
        }
Beispiel #5
0
        public static global::System.Diagnostics.Process createNativeProcess(string cmd, global::haxe.root.Array args)
        {
            unchecked {
                                #line 52 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                global::System.Diagnostics.Process native = new global::System.Diagnostics.Process();
                native.StartInfo.CreateNoWindow = ((bool)(true));
                                #line 54 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                native.StartInfo.RedirectStandardError = ((bool)(native.StartInfo.RedirectStandardInput = ((bool)(native.StartInfo.RedirectStandardOutput = ((bool)(true))))));
                if ((args != null))
                {
                                        #line 57 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                    if (((global::haxe.lang.StringExt.indexOf(cmd, "/", null) != -1) || (global::haxe.lang.StringExt.indexOf(cmd, "\\", null) != -1)))
                    {
                                                #line 58 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        cmd = global::sys.FileSystem.fullPath(cmd);
                    }

                                        #line 59 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                    native.StartInfo.FileName        = ((string)(cmd));
                    native.StartInfo.UseShellExecute = ((bool)(false));
                                        #line 61 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                    native.StartInfo.Arguments = ((string)(global::sys.io.Process.buildArgumentsString(args)));
                }
                else
                {
                                        #line 63 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                    if ((global::haxe.root.Sys.systemName() == "Windows"))
                    {
                                                #line 65 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        global::System.Diagnostics.ProcessStartInfo tmp = native.StartInfo;
                                                #line 65 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        string _g = global::System.Environment.GetEnvironmentVariable(((string)("COMSPEC")));
                                                #line 65 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        string tmp1 = null;
                        if ((_g == null))
                        {
                                                        #line 65 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                            tmp1 = "cmd.exe";
                        }
                        else
                        {
                                                        #line 67 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                            string comspec = _g;
                                                        #line 65 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                            tmp1 = comspec;
                        }

                                                #line 65 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        tmp.FileName = ((string)(tmp1));
                                                #line 69 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        native.StartInfo.Arguments = ((string)(global::haxe.lang.Runtime.concat(global::haxe.lang.Runtime.concat("/C \"", cmd), "\"")));
                    }
                    else
                    {
                                                #line 71 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                        native.StartInfo.FileName  = ((string)("/bin/sh"));
                        native.StartInfo.Arguments = ((string)(global::sys.io.Process.buildArgumentsString(new global::haxe.root.Array(new object[] { "-c", cmd }))));
                    }

                                        #line 74 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                    native.StartInfo.UseShellExecute = ((bool)(false));
                }

                                #line 76 "C:\\HaxeToolkit\\haxe\\std\\cs\\_std\\sys\\io\\Process.hx"
                return(native);
            }
                        #line default
        }
Beispiel #6
0
        static void ShellExecCmdLine(IntPtr hInstance, IntPtr hwnd, string command, string startDir, global::System.Diagnostics.ProcessWindowStyle nShow, ShellExecCmdLineFlags dwSeclFlags, bool runAsAdministrator = false, bool leaveCmdOpen = false)
        {
            string cmd  = command;
            string args = null;

            if (UrlIs(command, URLIS_URL))
            {
                cmd = command;
            }
            else
            {
                if (global::System.Environment.OSVersion.Version.Major >= 6)
                {
                    EvaluateSystemAndUserCommandLine(cmd, startDir, out cmd, out args, dwSeclFlags);
                }
                else
                {
                    EvaluateUserCommandLine(cmd, startDir, out cmd, out args);
                }
            }

            if (!UrlIs(cmd, URLIS_URL) &&
                (
                    (dwSeclFlags & ShellExecCmdLineFlags.SECL_USEFULLPATHDIR) == ShellExecCmdLineFlags.SECL_USEFULLPATHDIR ||
                    startDir == null ||
                    startDir.Length == 0))
            {
                string dir = QualifyWorkingDir(cmd);
                if (dir != null)
                {
                    startDir = dir;
                }
            }

            if (leaveCmdOpen && File.Exists(cmd))
            {
                bool needsCommandLine;

                try
                {
                    var peHeaderReader = new PeHeaderReader(cmd);

                    if (peHeaderReader.Is32BitHeader)
                    {
                        needsCommandLine = peHeaderReader.OptionalHeader32.Subsystem == 3;                 // IMAGE_SUBSYSTEM_WINDOWS_CUI == 3
                    }
                    else
                    {
                        needsCommandLine = peHeaderReader.OptionalHeader64.Subsystem == 3;
                    }
                }

                catch (Exception)
                {
                    // Error reading the headers. We will try to run the command the standard way.
                    needsCommandLine = false;
                }

                if (needsCommandLine)
                {
                    string cmdExe;
                    string dummy;
                    EvaluateSystemAndUserCommandLine("cmd.exe", startDir, out cmdExe, out dummy, dwSeclFlags);

                    // check whether user typed >cmd, because we don't want to create 2 nested shells
                    if (cmdExe != cmd)
                    {
                        args = string.Format("/k {0} {1}", cmd, args);
                        cmd  = cmdExe;
                    }
                }
            }

            global::System.Diagnostics.ProcessStartInfo startInfo = new global::System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.Arguments       = args;
            startInfo.FileName        = cmd;
            if (runAsAdministrator)
            {
                startInfo.Verb = "runas";
            }
            startInfo.WindowStyle             = global::System.Diagnostics.ProcessWindowStyle.Normal;
            startInfo.ErrorDialog             = (dwSeclFlags | ShellExecCmdLineFlags.SECL_NO_UI) == 0;
            startInfo.ErrorDialogParentHandle = hwnd;
            startInfo.WorkingDirectory        = startDir;
            try
            {
                global::System.Diagnostics.Process.Start(startInfo);
            }
            catch (Exception e)
            {
                if (!startInfo.ErrorDialog)
                {
                    throw e;
                }
            }
        }
Beispiel #7
0
        static void ShellExecCmdLine(IntPtr hInstance, IntPtr hwnd, string command, string startDir, global::System.Diagnostics.ProcessWindowStyle nShow, ShellExecCmdLineFlags dwSeclFlags)
        {
            string cmd = command;
            string args = null;
            if (UrlIs(command, URLIS_URL))
                cmd = command;
            else
            {
                if (global::System.Environment.OSVersion.Version.Major >= 6)
                    EvaluateSystemAndUserCommandLine(cmd, startDir, out cmd, out args, dwSeclFlags);
                else
                    EvaluateUserCommandLine(cmd, startDir, out cmd, out args);
            }

            if (!UrlIs(cmd, URLIS_URL)
                && (
                    (dwSeclFlags & ShellExecCmdLineFlags.SECL_USEFULLPATHDIR) == ShellExecCmdLineFlags.SECL_USEFULLPATHDIR
                    || startDir == null
                    || startDir.Length == 0))
            {
                string dir = QualifyWorkingDir(cmd);
                if (dir != null)
                    startDir = dir;
            }

            global::System.Diagnostics.ProcessStartInfo startInfo = new global::System.Diagnostics.ProcessStartInfo();
            startInfo.UseShellExecute = true;
            startInfo.Arguments = args;
            startInfo.FileName = cmd;
            startInfo.WindowStyle = global::System.Diagnostics.ProcessWindowStyle.Normal;
            startInfo.ErrorDialog = (dwSeclFlags | ShellExecCmdLineFlags.SECL_NO_UI) == 0;
            startInfo.ErrorDialogParentHandle = hwnd;

            try
            {
                global::System.Diagnostics.Process.Start(startInfo);
            }
            catch (Exception e)
            {
                if (!startInfo.ErrorDialog)
                    throw e;
            }
        }