コード例 #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();
        }
コード例 #2
0
 public static int command(string cmd, global::Array <string> args)
 {
             #line 106 "/opt/haxe/std/cs/_std/Sys.hx"
     global::System.Diagnostics.Process proc = global::sys.io.Process.createNativeProcess(cmd, args);
     global::System.Diagnostics.DataReceivedEventHandler this1 = ((global::System.Diagnostics.DataReceivedEventHandler)((((global::Sys_command_107__Fun.__hx_current != null)) ? (global::Sys_command_107__Fun.__hx_current) : (global::Sys_command_107__Fun.__hx_current = ((global::Sys_command_107__Fun)(new global::Sys_command_107__Fun())))).Delegate));
     proc.OutputDataReceived += ((global::System.Diagnostics.DataReceivedEventHandler)(this1));
             #line 112 "/opt/haxe/std/cs/_std/Sys.hx"
     global::haxe.io.Output stderr = ((global::haxe.io.Output)(new global::cs.io.NativeOutput(((global::System.IO.Stream)(global::System.Console.OpenStandardError())))));
     global::System.Diagnostics.DataReceivedEventHandler this2 = ((global::System.Diagnostics.DataReceivedEventHandler)(new global::Sys_command_113__Fun(stderr).Delegate));
     proc.ErrorDataReceived += ((global::System.Diagnostics.DataReceivedEventHandler)(this2));
             #line 118 "/opt/haxe/std/cs/_std/Sys.hx"
     proc.Start();
     proc.BeginOutputReadLine();
             #line 120 "/opt/haxe/std/cs/_std/Sys.hx"
     proc.BeginErrorReadLine();
     proc.WaitForExit();
             #line 122 "/opt/haxe/std/cs/_std/Sys.hx"
     int exitCode = proc.ExitCode;
     (proc as global::System.ComponentModel.Component).Dispose();
             #line 124 "/opt/haxe/std/cs/_std/Sys.hx"
     return(exitCode);
 }
コード例 #3
0
        /// <inheritdoc />
        public IProcess LaunchProcess(string fileName, string workingDirectory, string arguments, bool readOutput, bool readError, bool noShellExecute)
        {
            logger.LogDebug("Launching process in {0}: {1} {2}", workingDirectory, fileName, arguments);
            var handle = new global::System.Diagnostics.Process();

            try
            {
                handle.StartInfo.FileName         = fileName;
                handle.StartInfo.Arguments        = arguments;
                handle.StartInfo.WorkingDirectory = workingDirectory;

                handle.StartInfo.UseShellExecute = !(noShellExecute || readOutput || readError);

                StringBuilder outputStringBuilder = null, errorStringBuilder = null, combinedStringBuilder = null;
                if (readOutput || readError)
                {
                    combinedStringBuilder = new StringBuilder();
                    if (readOutput)
                    {
                        outputStringBuilder = new StringBuilder();
                        handle.StartInfo.RedirectStandardOutput = true;
                        handle.OutputDataReceived += (sender, e) =>
                        {
                            combinedStringBuilder.Append(Environment.NewLine);
                            combinedStringBuilder.Append(e.Data);
                            outputStringBuilder.Append(Environment.NewLine);
                            outputStringBuilder.Append(e.Data);
                        };
                    }

                    if (readError)
                    {
                        errorStringBuilder = new StringBuilder();
                        handle.StartInfo.RedirectStandardError = true;
                        handle.ErrorDataReceived += (sender, e) =>
                        {
                            combinedStringBuilder.Append(Environment.NewLine);
                            combinedStringBuilder.Append(e.Data);
                            errorStringBuilder.Append(Environment.NewLine);
                            errorStringBuilder.Append(e.Data);
                        };
                    }
                }

                var lifetimeTask = AttachExitHandler(handle);

                handle.Start();
                try
                {
                    if (readOutput)
                    {
                        handle.BeginOutputReadLine();
                    }
                }
                catch (InvalidOperationException) { }
                try
                {
                    if (readError)
                    {
                        handle.BeginErrorReadLine();
                    }
                }
                catch (InvalidOperationException) { }

                return(new Process(handle, lifetimeTask, outputStringBuilder, errorStringBuilder, combinedStringBuilder, loggerFactory.CreateLogger <Process>(), false));
            }
            catch
            {
                handle.Dispose();
                throw;
            }
        }