コード例 #1
0
        private bool IsArm64Process()
        {
            if (Environment.OSVersion.Platform != PlatformID.Unix || !Environment.Is64BitProcess)
            {
                return(false);
            }

            try
            {
                var process = new global::System.Diagnostics.Process();
                process.StartInfo.FileName  = "uname";
                process.StartInfo.Arguments = "-m";
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.UseShellExecute        = false;
                process.Start();
                process.WaitForExit();
                var output = process.StandardOutput.ReadToEnd();

                return(output.Trim() == "aarch64");
            }
            catch
            {
                return(false);
            }
        }
コード例 #2
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();
        }
コード例 #3
0
        public static void ExecuteBatchScript(string fileName)
        {
            var process = new global::System.Diagnostics.Process
            {
                StartInfo = { FileName = fileName }
            };

            process.Start();
            process.WaitForExit();
        }
コード例 #4
0
        /// <summary>
        /// Start a process that runs the Notepad application.
        /// </summary>
        /// <param name="InProcess"></param>
        /// <param name="InFilePath"></param>
        /// <returns></returns>
        public static bool StartNotepad(
            this global::System.Diagnostics.Process InProcess, string InFilePath)
        {
            string exePath =
                Environment.ExpandEnvironmentVariables(@"%SystemRoot%\system32\notepad.exe");

            InProcess.StartInfo.FileName = exePath;

            InProcess.StartInfo.Arguments = InFilePath;

            bool rc = InProcess.Start();

            return(rc);
        }
コード例 #5
0
ファイル: PngCodecTest.cs プロジェクト: ItsVeryWindy/mono
		private bool IsArm64Process ()
		{
			if (Environment.OSVersion.Platform != PlatformID.Unix || !Environment.Is64BitProcess)
				return false;

			try {
				var process = new global::System.Diagnostics.Process ();
				process.StartInfo.FileName = "uname";
				process.StartInfo.Arguments = "-m";
				process.StartInfo.RedirectStandardOutput = true;
				process.StartInfo.UseShellExecute = false;
				process.Start ();
				process.WaitForExit ();
				var output = process.StandardOutput.ReadToEnd ();

				return output.Trim () == "aarch64";
			} catch {
				return false;
			}
		}
コード例 #6
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);
 }
コード例 #7
0
        private bool IsArm64Process()
        {
            if (!GDIPlus.RunningOnUnix())
            {
                return(false);
            }

            try {
                var process = new global::System.Diagnostics.Process();
                process.StartInfo.FileName  = "uname";
                process.StartInfo.Arguments = "-m";
                process.StartInfo.RedirectStandardOutput = true;
                process.StartInfo.UseShellExecute        = false;
                process.Start();
                process.WaitForExit();
                var output = process.StandardOutput.ReadToEnd();

                return(output.Trim() == "aarch64");
            } catch {
                return(false);
            }
        }
コード例 #8
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;
            }
        }
コード例 #9
0
        /// <inheritdoc />
        public IProcess LaunchProcess(
            string fileName,
            string workingDirectory,
            string arguments,
            bool readOutput,
            bool readError,
            bool noShellExecute)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (!noShellExecute && (readOutput || readError))
            {
                throw new InvalidOperationException("Requesting output/error reading requires noShellExecute to be true!");
            }

            logger.LogDebug(
                "{0}aunching process in {1}: {2} {3}",
                noShellExecute ? "L" : "Shell l",
                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;

                StringBuilder combinedStringBuilder = null;

                Task <string> outputTask      = null;
                Task <string> errorTask       = null;
                var           processStartTcs = new TaskCompletionSource <object>();
                if (readOutput || readError)
                {
                    combinedStringBuilder = new StringBuilder();

                    async Task <string> ConsumeReader(Func <TextReader> readerFunc)
                    {
                        var    stringBuilder = new StringBuilder();
                        string text;

                        await processStartTcs.Task.ConfigureAwait(false);

                        var reader = readerFunc();

                        while ((text = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
                        {
                            combinedStringBuilder.AppendLine();
                            combinedStringBuilder.Append(text);
                            stringBuilder.AppendLine();
                            stringBuilder.Append(text);
                        }

                        return(stringBuilder.ToString());
                    }

                    if (readOutput)
                    {
                        outputTask = ConsumeReader(() => handle.StandardOutput);
                        handle.StartInfo.RedirectStandardOutput = true;
                    }

                    if (readError)
                    {
                        errorTask = ConsumeReader(() => handle.StandardError);
                        handle.StartInfo.RedirectStandardError = true;
                    }
                }

                var lifetimeTaskTask = AttachExitHandlerBeforeLaunch(handle, processStartTcs.Task);

                try
                {
                    handle.Start();

                    processStartTcs.SetResult(null);
                }
                catch (Exception ex)
                {
                    processStartTcs.SetException(ex);
                    throw;
                }

                var process = new Process(
                    processFeatures,
                    handle,
                    lifetimeTaskTask.GetAwaiter().GetResult(),                     // won't block
                    outputTask,
                    errorTask,
                    combinedStringBuilder,
                    loggerFactory.CreateLogger <Process>(), false);

                return(process);
            }
            catch
            {
                handle.Dispose();
                throw;
            }
        }
コード例 #10
0
        /// <inheritdoc />
        public IProcess LaunchProcess(
            string fileName,
            string workingDirectory,
            string arguments,
            bool readOutput,
            bool readError,
            bool noShellExecute)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }
            if (workingDirectory == null)
            {
                throw new ArgumentNullException(nameof(workingDirectory));
            }
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (!noShellExecute && (readOutput || readError))
            {
                throw new InvalidOperationException("Requesting output/error reading requires noShellExecute to be true!");
            }

            logger.LogDebug(
                "{0}aunching process in {1}: {2} {3}",
                noShellExecute ? "L" : "Shell l",
                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;

                StringBuilder outputStringBuilder = null, errorStringBuilder = null, combinedStringBuilder = null;

                TaskCompletionSource <object> outputReadTcs = null;
                TaskCompletionSource <object> errorReadTcs  = null;
                if (readOutput || readError)
                {
                    combinedStringBuilder = new StringBuilder();
                    if (readOutput)
                    {
                        outputStringBuilder = new StringBuilder();
                        handle.StartInfo.RedirectStandardOutput = true;
                        outputReadTcs              = new TaskCompletionSource <object>();
                        handle.OutputDataReceived += (sender, e) =>
                        {
                            if (e.Data == null)
                            {
                                outputReadTcs.SetResult(null);
                                return;
                            }

                            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;
                        errorReadTcs              = new TaskCompletionSource <object>();
                        handle.ErrorDataReceived += (sender, e) =>
                        {
                            if (e.Data == null)
                            {
                                errorReadTcs.SetResult(null);
                                return;
                            }

                            combinedStringBuilder.Append(Environment.NewLine);
                            combinedStringBuilder.Append(e.Data);
                            errorStringBuilder.Append(Environment.NewLine);
                            errorStringBuilder.Append(e.Data);
                        };
                    }
                }

                var lifetimeTask = AttachExitHandler(handle);

                handle.Start();