public void TestProcess() { //打开百度 ProcessUtils.Execute(@"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "http://www.baidu.com"); //ProcessUtils.Shutdown(); }
public static ExecutionResult ExecuteCommand(ExecutionCommand command) { var sw = Stopwatch.StartNew(); try { var args = string.Join(" ", command.AsArguments()); var executionResult = ProcessUtils.Execute(args, command.Deadline + 10); executionResult.ExecutionCommand = command; return(executionResult); } catch (Exception ex) { Console.WriteLine($"Error while executing command {command.Command}: {ex}"); return(new ExecutionResult { Code = ExecutionStatus.FatalError, Status = ExecutionStatus.FatalError.ToString(), Duration = sw.ElapsedMilliseconds / 1000.0, Message = "Unknown error", Messages = ex.StackTrace?.Split("\n").ToList() ?? new List <string> { "Could not determine stacktrace" }, ExecutionCommand = command, ReturnCode = 666, }); } }
public void OnStartRecording() { UILabel label; var assetsPath = Application.streamingAssetsPath; // stop recording if (recordProcess != null) { #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX ProcessUtils.Execute("/usr/bin/killall", "ffmpeg"); if (!recordProcess.HasExited) { recordProcess.Kill(); } #endif #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN var args = "/c" + assetsPath + "\\STOPffmpeg.bat"; var res = ProcessUtils.Execute("C:\\Windows\\system32\\cmd.exe", args); Debug.Log("STOPffmpeg: " + res); #endif label = recordButton.GetComponentInChildren <UILabel>(); label.text = "Record"; recordProcess = null; return; } // TODO: remove this or use it to generate scripts? // TestFFMpeg(); var process = new System.Diagnostics.Process(); process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; string outputFilename; #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN outputFilename = "testvideo.mkv"; process.StartInfo.FileName = "C:\\Windows\\system32\\cmd.exe"; process.StartInfo.Arguments = "/c" + assetsPath + "\\STARTffmpeg.bat " + outputFilename; #endif #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX outputFilename = "/Users/ryanjoseph/Desktop/testvid.mp4"; process.StartInfo.FileName = "/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal"; // TODO: can't get params on Mac??? // process.StartInfo.Arguments = assetsPath+"/ffmpeg_record.bash \""+outputFilename+"\""; // process.StartInfo.Arguments = assetsPath+"/ffmpeg_record.bash"; process.StartInfo.Arguments = "/Users/ryanjoseph/Downloads/ffmpeg_record.bash"; #endif // process.EnableRaisingEvents = true; process.Start(); // process.WaitForExit(); // Debug.Log("process exited:"+process.ExitCode); Debug.Log("process started: " + process.Id); recordProcess = process; label = recordButton.GetComponentInChildren <UILabel>(); label.text = "Stop"; }
public async Task <int> RunAsync(CommandLineArgs args) { var index = 1; var commits = _Git.GetTotalCommits().Each(x => x.Index = index++); Print(commits); int n; while ((n = ReadIgnore(commits.Length)) != 0) { switch (n) { case -1: { Print(commits); break; } case -2: { Console.WriteLine("your input is not valid."); break; } default: { index = 1; commits = commits.Remove(x => x.Index == n).Each(x => x.Index = index++); Print(commits); break; } } } var files = new GitFile[0]; index = 0; Console.Write($"\r1st phrase: {index++}/{commits.Length}"); foreach (var commit in commits.OrderBy(x => x.Date)) { var changes = _Git.GetCommitDetail(commit.Id); foreach (var change in changes) { var exists = files.FirstOrDefault(x => x.Path.EqualsIgnoreCase(change.Path)); if (exists == null) { var file = new GitFile() { InitialCommit = commit, LatestCommit = commit, InitialAction = change.Action, LatestAction = change.Action, Path = change.Path, }; files = files.Append(file); } else { exists.LatestCommit = commit; exists.LatestAction = change.Action; } } Console.Write($"\r1st phrase: {index++}/{commits.Length}"); } // A -> A -> A: N/A // A -> A -> M: N/A // A -> A -> D: N/A // A -> M -> A: Compare // A -> M -> M: Compare // A -> M -> D: Delete // A -> D -> A: Compare // A -> D -> M: Compare // A -> D -> D: Delete // M -> A -> A: N/A // M -> A -> M: N/A // M -> A -> D: N/A // M -> M -> A: Compare // M -> M -> M: Compare // M -> M -> D: Delete // M -> D -> A: Compare // M -> D -> M: Compare // M -> D -> D: Delete // . -> A -> A: Add // . -> A -> M: Add // . -> A -> D: Ignore index = 0; ClearCurrentLine(); foreach (var file in files) { Console.Write($"\r2nd phrase: {index++}/{files.Length}"); if ((file.InitialAction == "M" && file.LatestAction == "A") || (file.InitialAction == "M" && file.LatestAction == "M") || (file.InitialAction == "D" && file.LatestAction == "A") || (file.InitialAction == "D" && file.LatestAction == "M")) { var commit = _Git.GetFileHistory(file.Path, file.InitialCommit); if (commit != null) { file.HistoryCommit = commit; var historyContent = _Git.GetFileContent(file.HistoryCommit.Id, file.Path); var latestContent = _Git.GetFileContent(file.LatestCommit.Id, file.Path); if (historyContent == latestContent) { file.Mark = "I"; continue; } } file.Mark = "M"; continue; } if ((file.InitialAction == "M" && file.LatestAction == "D") || (file.InitialAction == "D" && file.LatestAction == "D")) { var commit = _Git.GetFileHistory(file.Path, file.InitialCommit); if (commit != null) { file.HistoryCommit = commit; } file.Mark = "D"; continue; } if ((file.InitialAction == "A" && file.LatestAction == "A") || (file.InitialAction == "A" && file.LatestAction == "M")) { file.Mark = "A"; continue; } if (file.InitialAction == "A" && file.LatestAction == "D") { file.Mark = "I"; continue; } } ClearCurrentLine(); index = 1; var compares = files.Where(x => x.Mark != "I").OrderBy(x => x.Mark).ThenBy(x => x.Path).ToArray().Each(x => x.Index = index++); // print results Print(compares); // wait input from user while ((n = ReadCompare(compares.Length)) != 0) { switch (n) { case -1: { Print(compares); break; } case -2: { Console.WriteLine("your input is not valid."); break; } default: { var compare = compares.FirstOrDefault(x => x.Index == n); if (compare.Mark == "M" && compare.HistoryCommit != null) { Console.WriteLine($"compare {compare.HistoryCommit.Id} to {compare.LatestCommit.Id}"); if (!"./tempfiles".IsFolder()) { Directory.CreateDirectory("./tempfiles".FullPath()); } var history = $"./tempfiles/{compare.HistoryCommit.Id.Substring(0, 6)}-{compare.FileName}".FullPath(); using (var outputStream = new FileStream(history, FileMode.Create, FileAccess.Write)) { using (var writer = new StreamWriter(outputStream)) { writer.Write(_Git.GetFileContent(compare.HistoryCommit.Id, compare.Path)); } } var latest = $"./tempfiles/{compare.LatestCommit.Id.Substring(0, 6)}-{compare.FileName}".FullPath(); using (var outputStream = new FileStream(latest, FileMode.Create, FileAccess.Write)) { using (var writer = new StreamWriter(outputStream)) { writer.Write(_Git.GetFileContent(compare.LatestCommit.Id, compare.Path)); } } var config = DependencyContainer.Resolve <IAppConfiguration>(); ProcessUtils.Execute( config.CompareTool, $"{config.CompareToolParams ?? string.Empty} \"{history}\" \"{latest}\"", null); } else if (compare.Mark == "A") { Console.WriteLine($"{compare.Path} Added."); if (!"./tempfiles".IsFolder()) { Directory.CreateDirectory("./tempfiles".FullPath()); } var history = "./tempfiles/empty".FullPath(); if (!history.IsFile()) { using (var outputStream = new FileStream(history, FileMode.Create, FileAccess.Write)) { } } var latest = $"./tempfiles/{compare.LatestCommit.Id.Substring(0, 6)}-{compare.FileName}".FullPath(); using (var outputStream = new FileStream(latest, FileMode.Create, FileAccess.Write)) { using (var writer = new StreamWriter(outputStream)) { writer.Write(_Git.GetFileContent(compare.LatestCommit.Id, compare.Path)); } } var config = DependencyContainer.Resolve <IAppConfiguration>(); ProcessUtils.Execute( config.CompareTool, $"{config.CompareToolParams ?? string.Empty} \"{history}\" \"{latest}\"", null); } else if (compare.Mark == "D" && compare.HistoryCommit != null) { Console.WriteLine($"{compare.Path} Deleted."); if (!"./tempfiles".IsFolder()) { Directory.CreateDirectory("./tempfiles".FullPath()); } var history = $"./tempfiles/{compare.HistoryCommit.Id.Substring(0, 6)}-{compare.FileName}".FullPath(); using (var outputStream = new FileStream(history, FileMode.Create, FileAccess.Write)) { using (var writer = new StreamWriter(outputStream)) { writer.Write(_Git.GetFileContent(compare.HistoryCommit.Id, compare.Path)); } } var latest = "./tempfiles/empty".FullPath(); if (!latest.IsFile()) { using (var outputStream = new FileStream(latest, FileMode.Create, FileAccess.Write)) { } } var config = DependencyContainer.Resolve <IAppConfiguration>(); ProcessUtils.Execute( config.CompareTool, $"{config.CompareToolParams ?? string.Empty} \"{history}\" \"{latest}\"", null); } break; } } } return(await Task.FromResult(0)); }