private static Tuple <int, string> ExecuteProcess(string fileName, string arguments) { var exitCode = 0; // タイムアウト時間 (120秒). var timeout = TimeSpan.FromSeconds(120); // ログ. var compileLog = new StringBuilder(); using (var process = new System.Diagnostics.Process()) { var processStartInfo = new System.Diagnostics.ProcessStartInfo { FileName = fileName, Arguments = arguments, // エラー出力をリダイレクト. RedirectStandardOutput = true, RedirectStandardError = true, // シェル実行しない. UseShellExecute = false, // ウィンドウ非表示. CreateNoWindow = true, WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden, }; process.StartInfo = processStartInfo; System.Diagnostics.DataReceivedEventHandler processOutputDataReceived = (sender, e) => { compileLog.AppendLine(e.Data); }; process.OutputDataReceived += processOutputDataReceived; //起動. process.Start(); process.BeginOutputReadLine(); // 結果待ち. process.WaitForExit((int)timeout.TotalMilliseconds); // 終了コード. exitCode = process.ExitCode; } return(new Tuple <int, string>(exitCode, compileLog.ToString())); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { FASTBuildPackage fbPackage = (FASTBuildPackage)this.package; if (null == fbPackage.m_dte.Solution) { return; } MenuCommand eventSender = sender as MenuCommand; fbPackage.m_outputPane.Activate(); fbPackage.m_outputPane.Clear(); if (eventSender == null) { fbPackage.m_outputPane.OutputString("VSIX failed to cast sender to OleMenuCommand.\r"); return; } if (fbPackage.m_dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode) { fbPackage.m_outputPane.OutputString("Build not launched due to active debugger.\r"); return; } if (!IsFBuildFindable(fbPackage.OptionFBPath)) { fbPackage.m_outputPane.OutputString(string.Format("Could not find fbuild at the provided path: {0}, please verify in the msfastbuild options.\r", fbPackage.OptionFBPath)); return; } fbPackage.m_dte.ExecuteCommand("File.SaveAll"); string fbCommandLine = ""; string fbWorkingDirectory = ""; Solution sln = fbPackage.m_dte.Solution; SolutionBuild sb = sln.SolutionBuild; SolutionConfiguration2 sc = sb.ActiveConfiguration as SolutionConfiguration2; VCProject proj = null; if (eventSender.CommandID.ID != SlnCommandId && eventSender.CommandID.ID != SlnContextCommandId) { if (fbPackage.m_dte.SelectedItems.Count > 0) { Project envProj = (fbPackage.m_dte.SelectedItems.Item(1).Project as EnvDTE.Project); if (envProj != null) { proj = envProj.Object as VCProject; } } if (proj == null) { string startupProject = ""; foreach (String item in (Array)sb.StartupProjects) { startupProject += item; } proj = sln.Item(startupProject).Object as VCProject; } if (proj == null) { fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r"); return; } fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r"); fbCommandLine = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -e \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile); } else { fbCommandLine = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3}\" -e \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(sln.FileName); } if (fbPackage.OptionBrokerage.Length > 0) { fbCommandLine += " -b " + fbPackage.OptionBrokerage; } if (fbPackage.OptionFBUnity) { fbCommandLine += " -u true"; } string msfastbuildPath = Assembly.GetAssembly(typeof(msfastbuild.msfastbuild)).Location; try { fbPackage.m_outputPane.OutputString("Launching msfastbuild with command line: " + fbCommandLine + "\r"); System.Diagnostics.Process FBProcess = new System.Diagnostics.Process(); FBProcess.StartInfo.FileName = msfastbuildPath; FBProcess.StartInfo.Arguments = fbCommandLine; FBProcess.StartInfo.WorkingDirectory = fbWorkingDirectory; FBProcess.StartInfo.RedirectStandardOutput = true; FBProcess.StartInfo.UseShellExecute = false; FBProcess.StartInfo.CreateNoWindow = true; var SystemEncoding = System.Globalization.CultureInfo.GetCultureInfo(GetSystemDefaultLCID()).TextInfo.OEMCodePage; FBProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(SystemEncoding); System.Diagnostics.DataReceivedEventHandler OutputEventHandler = (Sender, Args) => { if (Args.Data != null) { fbPackage.m_outputPane.OutputString(Args.Data + "\r"); } }; FBProcess.OutputDataReceived += OutputEventHandler; FBProcess.Start(); FBProcess.BeginOutputReadLine(); //FBProcess.WaitForExit(); } catch (Exception ex) { fbPackage.m_outputPane.OutputString("VSIX exception launching msfastbuild. Could be a broken VSIX? Exception: " + ex.Message + "\r"); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { FASTBuildPackage fbPackage = (FASTBuildPackage)this.package; if (null == fbPackage.m_dte.Solution) return; MenuCommand eventSender = sender as MenuCommand; fbPackage.m_outputPane.Activate(); fbPackage.m_outputPane.Clear(); if (eventSender == null) { fbPackage.m_outputPane.OutputString("VSIX failed to cast sender to OleMenuCommand.\r"); return; } if (fbPackage.m_dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode) { fbPackage.m_outputPane.OutputString("Build not launched due to active debugger.\r"); return; } if (!IsFBuildFindable(fbPackage.OptionFBPath)) { fbPackage.m_outputPane.OutputString(string.Format("Could not find fbuild at the provided path: {0}, please verify in the msfastbuild options.\r", fbPackage.OptionFBPath)); return; } fbPackage.m_dte.ExecuteCommand("File.SaveAll"); string fbCommandLine = ""; string fbWorkingDirectory = ""; Solution sln = fbPackage.m_dte.Solution; SolutionBuild sb = sln.SolutionBuild; SolutionConfiguration2 sc = sb.ActiveConfiguration as SolutionConfiguration2; VCProject proj = null; if (eventSender.CommandID.ID == ContextCommandId) { if (fbPackage.m_dte.SelectedItems.Count > 0) { Project envProj = (fbPackage.m_dte.SelectedItems.Item(1).Project as EnvDTE.Project); if (envProj != null) { proj = envProj.Object as VCProject; } } if (proj == null) { string startupProject = ""; foreach (String item in (Array)sb.StartupProjects) { startupProject += item; } proj = sln.Item(startupProject).Object as VCProject; } if (proj == null) { fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r"); return; } fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r"); fbCommandLine = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -b \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile); } else if (eventSender.CommandID.ID == CommandId) { if (fbPackage.m_dte.ActiveDocument == null || fbPackage.m_dte.ActiveDocument.ProjectItem == null || fbPackage.m_dte.ActiveDocument.ProjectItem.ContainingProject == null) { fbPackage.m_outputPane.OutputString("No valid vcproj selected for building.\r"); return; } Project envProj = fbPackage.m_dte.ActiveDocument.ProjectItem.ContainingProject; if (envProj != null) { proj = envProj.Object as VCProject; } if (proj == null) { fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r"); return; } fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r"); fbCommandLine = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -b \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile); } else if (eventSender.CommandID.ID == SlnCleanCommandId || eventSender.CommandID.ID == SlnContextCleanCommandId) { fbCommandLine = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3} -clean\" -b \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(sln.FileName); fbPackage.m_dte.Solution.SolutionBuild.Clean(true); fbPackage.m_outputPane.Activate(); } else if (eventSender.CommandID.ID == SlnCleanBffCommandId) { fbWorkingDirectory = Path.GetDirectoryName(sln.FileName); var files = Directory.EnumerateFiles(fbWorkingDirectory, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".fdb") || s.EndsWith(".bff")); foreach (string file in files) { File.Delete(file); } fbPackage.m_outputPane.OutputString("bff file deleted.\r"); fbPackage.m_outputPane.OutputString("========== 정리: 성공 ==========\r"); Window output_window = fbPackage.m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); output_window.Activate(); return; } else if (eventSender.CommandID.ID == SlnStopCommandId) { if (FBProcess == null) { return; } if (FBProcess.HasExited) { return; } FBProcess.CancelOutputRead(); FBProcess.Kill(); fbPackage.m_outputPane.OutputString("빌드가 취소되었습니다.\r"); Window output_window = fbPackage.m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); output_window.Activate(); return; } else { fbCommandLine = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3}\" -b \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath); fbWorkingDirectory = Path.GetDirectoryName(sln.FileName); } if (fbPackage.OptionFBUnity) { fbCommandLine += " -u true"; } if (fbPackage.OptionFBUseRelative) { fbCommandLine += " -t true"; } if (fbPackage.OptionFBUseLightCache) { fbCommandLine += " -l true"; } string msfastbuildPath = Assembly.GetAssembly(typeof(msfastbuild.msfastbuild)).Location; try { fbPackage.m_outputPane.OutputString("Launching msfastbuild with command line: " + fbCommandLine + "\r"); FBProcess = new System.Diagnostics.Process(); FBProcess.StartInfo.FileName = msfastbuildPath; FBProcess.StartInfo.Arguments = fbCommandLine; FBProcess.StartInfo.WorkingDirectory = fbWorkingDirectory; FBProcess.StartInfo.RedirectStandardOutput = true; FBProcess.StartInfo.UseShellExecute = false; FBProcess.StartInfo.CreateNoWindow = true; var SystemEncoding = System.Globalization.CultureInfo.GetCultureInfo(GetSystemDefaultLCID()).TextInfo.OEMCodePage; FBProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(SystemEncoding); System.Diagnostics.DataReceivedEventHandler OutputEventHandler = (Sender, Args) => { if (Args.Data != null) fbPackage.m_outputPane.OutputString(Args.Data + "\r"); }; FBProcess.OutputDataReceived += OutputEventHandler; FBProcess.Start(); FBProcess.BeginOutputReadLine(); //FBProcess.WaitForExit(); } catch (Exception ex) { fbPackage.m_outputPane.OutputString("VSIX exception launching msfastbuild. Could be a broken VSIX? Exception: " + ex.Message + "\r"); } Window window = fbPackage.m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); window.Activate(); }
private static string ShellExecuteCmd(string verb, string fileName, string arguments, string[] cmdLines, bool isWaitForExit, bool isAysnc, EventHandler exitHander, System.Diagnostics.DataReceivedEventHandler dataReceived, System.Diagnostics.DataReceivedEventHandler errorReceived) { System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); startInfo.FileName = fileName; if (!string.IsNullOrEmpty(arguments)) { startInfo.Arguments = arguments; } startInfo.UseShellExecute = false; startInfo.RedirectStandardInput = true; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; startInfo.CreateNoWindow = true; if (!string.IsNullOrEmpty(verb)) { startInfo.Verb = verb; } string text = null; using (System.Diagnostics.Process proc = new System.Diagnostics.Process()) { proc.StartInfo = startInfo; if (isAysnc) { if (dataReceived != null) { proc.OutputDataReceived += dataReceived; } if (errorReceived != null) { proc.ErrorDataReceived += errorReceived; } } proc.EnableRaisingEvents = true; proc.Exited += exitHander; proc.Start(); if (cmdLines != null) { using (System.IO.StreamWriter writer = proc.StandardInput) { foreach (var line in cmdLines) { proc.StandardInput.WriteLine(line); } } if (isAysnc) { proc.BeginOutputReadLine(); proc.BeginErrorReadLine(); } else { text = proc.StandardOutput.ReadToEnd(); } } if (isWaitForExit) { proc.WaitForExit(); } } return(text); }
public static string ExecuteCmd(string fileName, string arguments, string[] cmdLines, bool isWaitForExit, bool isAysnc, EventHandler exitHander, System.Diagnostics.DataReceivedEventHandler dataReceived, System.Diagnostics.DataReceivedEventHandler errorReceived) { return(ShellExecuteCmd("", fileName, arguments, cmdLines, isWaitForExit, isAysnc, exitHander, dataReceived, errorReceived)); }
public static string AdminRunCmd(string arguments, string[] cmdLines, bool isWaitForExit, bool isAysnc, EventHandler exitHander, System.Diagnostics.DataReceivedEventHandler dataReceived, System.Diagnostics.DataReceivedEventHandler errorReceived) { return(AdminExecuteCmd("cmd.exe", arguments, cmdLines, isWaitForExit, isAysnc, exitHander, dataReceived, errorReceived)); }
public static void AsyncImmediateRunCmd(string cmdLine, System.Diagnostics.DataReceivedEventHandler dataReceived, System.Diagnostics.DataReceivedEventHandler errorReceived) { RunCmd(null, new string[] { cmdLine }, true, true, null, dataReceived, errorReceived); }
// /// <summary> // /// Coroutine that checks an .OBJ's mesh information. // /// </summary> // /// <param name="caller"></param> The object calling this method. // /// <param name="inputFilePath"></param> The full path to the input .OBJ file. // /// <param name="storeFaceCount"></param> Action that stores the mesh's face count. // /// <returns></returns> // public static IEnumerator RunCheckOBJMeshInfoCoroutine(MonoBehaviour caller, string inputFilePath, System.Diagnostics.DataReceivedEventHandler storeFaceCount) // { // // Indicate to the user that the process has started. // GeneralToolkit.ResetCancelableProgressBar(true, false); // // Initialize the coroutine parameters. // bool displayProgressBar; bool stopOnError; string[] progressBarParams; // InitBlenderCoroutineParams(false, out displayProgressBar, out stopOnError, out progressBarParams); // progressBarParams[1] = "Check .OBJ mesh information"; // // Launch the command. // string command = FormatBlenderCommand(_checkOBJMeshInfoFileName, inputFilePath); // yield return caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, storeFaceCount, _harmlessWarnings, stopOnError, progressBarParams)); // // Indicate to the user that the process has ended. // GeneralToolkit.ResetCancelableProgressBar(false, false); // } /// <summary> /// Coroutine that simplifies the mesh in a .OBJ file using the decimation modifier. /// </summary> /// <param name="caller"></param> The Blender helper calling this method. /// <param name="inputFilePath"></param> The full path to the input .OBJ file. /// <param name="outputFilePath"></param> The full path to the output .OBJ file. /// <param name="storeFaceCount"></param> Action that stores the mesh's face count. /// <returns></returns> public static IEnumerator RunSimplifyOBJCoroutine(BlenderHelper caller, string inputFilePath, string outputFilePath, System.Diagnostics.DataReceivedEventHandler storeFaceCount) { // Indicate to the user that the process has started. GeneralToolkit.ResetCancelableProgressBar(true, true); // Initialize the coroutine parameters. bool displayProgressBar; bool stopOnError; string[] progressBarParams; InitBlenderCoroutineParams(true, out displayProgressBar, out stopOnError, out progressBarParams); progressBarParams[1] = "Convert .PLY to .OBJ"; // Launch the command. string command = FormatBlenderCommand(_simplifyOBJFileName, inputFilePath, outputFilePath); yield return(caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, storeFaceCount, _harmlessWarnings, stopOnError, progressBarParams))); // Display the simplified mesh in the Scene view. caller.DisplayMeshInSceneView(outputFilePath); // Indicate to the user that the process has ended. GeneralToolkit.ResetCancelableProgressBar(false, false); }
/// <summary> /// Coroutine that simplifies the mesh in a .OBJ file using the decimation modifier. /// </summary> /// <param name="caller"></param> The object calling this method. /// <param name="inputFilePath"></param> The full path to the input .OBJ file. /// <param name="outputFilePath"></param> The full path to the output .OBJ file. /// <param name="storeFaceCount"></param> Action that stores the mesh's face count. /// <returns></returns> public static IEnumerator RunSimplifyOBJCoroutine(MonoBehaviour caller, string inputFilePath, string outputFilePath, System.Diagnostics.DataReceivedEventHandler storeFaceCount) { // Initialize the coroutine. bool displayProgressBar; bool stopOnError; string[] progressBarParams; InitBlenderCoroutine(true, out displayProgressBar, out stopOnError, out progressBarParams); progressBarParams[1] = "Convert .PLY to .OBJ"; // Launch the command. string command = FormatBlenderCommand(_simplifyOBJFileName, inputFilePath, outputFilePath); yield return(caller.StartCoroutine(GeneralToolkit.RunCommandCoroutine(typeof(BlenderConnector), command, _externalPythonScriptsDir, displayProgressBar, storeFaceCount, _harmlessWarnings, stopOnError, progressBarParams))); // Clear the coroutine. ClearBlenderCoroutine(); }
public static IEnumerator Execute(string exe, string prmt , System.Diagnostics.DataReceivedEventHandler OutputDataReceived = null , Action end = null , float total = 0, string processingtag = "bash", string info = "" ) { bool finished = false; var process = new System.Diagnostics.Process(); var processing = 0f; try { // UnityEngine.Debug.Log(exe + " " + prmt); var pi = new System.Diagnostics.ProcessStartInfo(exe, prmt); pi.WorkingDirectory = "."; pi.RedirectStandardInput = false; pi.RedirectStandardOutput = true; pi.RedirectStandardError = true; pi.UseShellExecute = false; pi.CreateNoWindow = true; if (OutputDataReceived != null) { process.OutputDataReceived += OutputDataReceived; } process.OutputDataReceived += (sender, e) => { if (string.IsNullOrEmpty(e.Data)) { return; } if (e.Data.StartsWith(processingtag)) { ++processing; } // UnityEngine.Debug.Log(e.Data); }; process.ErrorDataReceived += (sender, e) => { if (!string.IsNullOrEmpty(e.Data)) { UnityEngine.Debug.LogError(e.GetType() + ": " + e.Data); } }; process.Exited += (object sender, EventArgs e) => { finished = true; UnityEngine.Debug.Log("Exit"); }; process.StartInfo = pi; process.EnableRaisingEvents = true; process.Start(); process.BeginOutputReadLine(); process.BeginErrorReadLine(); // process.WaitForExit(); } catch (Exception e) { UnityEngine.Debug.LogError("catch: " + e); } while (!finished) { if (total > 1) { EditorUtility.DisplayCancelableProgressBar("uploading ...", info + ": " + processing + "/" + total, processing / total); } yield return(null); } if (end != null) { end(); } // UnityEngine.Debug.Log("finished: " + process.ExitCode); EditorUtility.ClearProgressBar(); yield return(null); }
public override void RunSimulation(System.Diagnostics.DataReceivedEventHandler outputDataReceived, System.Diagnostics.DataReceivedEventHandler errorDataReceived, EventHandler exited) { throw new NotImplementedException(); }