Example #1
0
        public void RunAnonymousScript(string script, CommandOptions options, string workingDirectory = null)
        {
            string scriptExecutable = PathUtility.GetFileNameFromCommand(script);

            if (!PathUtility.TryGetPathFile(scriptExecutable, RuntimeInfo, out string fileName))
            {
                fileName = RuntimeInfo.IsWindows ? "powershell.exe" : "bash";
            }
            else
            {
                script = script.Remove(0, scriptExecutable.Length);
            }

            if (options.Verbose)
            {
                _console.WriteDefaultLine($"Executing '{fileName} {script}'");
            }

            using (var process = ProcessUtility.CreateProcess(fileName, script, _fileSystem, workingDirectory))
            {
                process.ErrorDataReceived += ProcessUtility.WriteOutput(_console, ConsoleLogLevel.Error);
                if (options.Verbose)
                {
                    process.OutputDataReceived += ProcessUtility.WriteOutput(_console);
                }

                process.Start();

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                process.WaitForExit(5000);
            }
        }
Example #2
0
        /// <summary>
        /// Webサイトにアクセスする。
        /// ブラウザが見つからない場合はFileNotFoundExceptionを投げる。
        /// </summary>
        /// <param name="url">WebサイトのURL</param>
        public static void AccessWebsite(Uri websiteUrl)
        {
            // ブラウザが見つからない場合には例外を投げる
            if (File.Exists(UserSetting.BrowserPath) == false)
            {
                throw new FileNotFoundException("Not found web browser.");
            }
            if (websiteUrl == null)
            {
                return;
            }

            ProcessUtility.CreateProcess(UserSetting.BrowserPath, websiteUrl.ToString());
        }
Example #3
0
        /// <summary>
        /// ストリーミングを再生する。
        /// 再生用プログラムが見つからない場合はFileNotFoundExceptionを投げる。
        /// </summary>
        /// <param name="streamingUrl">ストリーミングのURL</param>
        public static void PlayStreaming(Uri streamingUrl)
        {
            // 再生用メディアプレイヤーが見つからない場合には例外を投げる
            if (File.Exists(UserSetting.MediaPlayerPath) == false)
            {
                throw new FileNotFoundException("Not found media player.");
            }
            if (streamingUrl == null)
            {
                return;
            }

            ProcessUtility.CreateProcess(UserSetting.MediaPlayerPath, streamingUrl.ToString());
        }
Example #4
0
        /// <summary>
        /// 音声ファイルを再生する。
        /// 再生用プログラムが見つからない場合はFileNotFoundExceptionを投げる。
        /// </summary>
        /// <param name="filePath">音声ファイルのパス</param>
        public static void PlayStreaming(string filePath)
        {
            // 再生用メディアプレイヤーが見つからない場合には例外を投げる
            if (File.Exists(UserSetting.MediaPlayerPath) == false)
            {
                throw new FileNotFoundException("Not found media player.");
            }
            if (filePath == string.Empty)
            {
                return;
            }

            ProcessUtility.CreateProcess(UserSetting.MediaPlayerPath, "\"" + filePath + "\"");
        }
Example #5
0
        public void CreateProcess_returns_process_with_fileName_and_arguments_in_target_directory()
        {
            string targetDirectory = PathHelper.GetSampleProjectPath("ConfigurationGood");

            _fileSystem.WorkingDirectory = targetDirectory;

            var process = ProcessUtility.CreateProcess("wumbo", "--foo bar", _fileSystem);

            Assert.Equal("wumbo", process.StartInfo.FileName);
            Assert.Equal("--foo bar", process.StartInfo.Arguments);
            Assert.Equal(targetDirectory, process.StartInfo.WorkingDirectory);
            Assert.True(process.StartInfo.RedirectStandardOutput);
            Assert.True(process.StartInfo.RedirectStandardError);
            Assert.True(process.StartInfo.RedirectStandardInput);
            Assert.False(process.StartInfo.UseShellExecute);
        }