//========================================================================================== // Methods //========================================================================================== /// <summary> /// Executes the command line, piping output to the specified output pane. /// </summary> /// <param name="outputPane">The output pane to write message to.</param> /// <param name="launchPadEvents">Receives event callbacks on the progress of the process.</param> /// <returns>Value returned by the process.</returns> public int ExecuteCommand(IVsOutputWindowPane outputPane, IVsLaunchPadEvents launchPadEvents) { Tracer.VerifyNonNullArgument(outputPane, "outputPane"); Tracer.VerifyNonNullArgument(launchPadEvents, "launchPadEvents"); // Create the IVsLaunchPad object if it hasn't been created yet. if (this.launchPad == null) { this.launchPad = this.CreateLaunchPad(); } uint processExitCode; uint flags = unchecked ((uint)this.Flags); uint taskPadCategory = unchecked ((uint)this.TaskPadCategory); uint taskItemBitmap = unchecked ((uint)this.TaskItemBitmap); int hr = this.launchPad.ExecCommand(null, this.CommandLine, this.WorkingDirectory, flags, outputPane, taskPadCategory, taskItemBitmap, null, launchPadEvents, out processExitCode, null); if (NativeMethods.Failed(hr)) { string debugMessage = PackageUtility.SafeStringFormatInvariant("Error in attempting to launch command '{0}': Hr=0x{1:x}", this.CommandLine, hr); Package.Instance.Context.NotifyInternalError(ResourceId.IDS_E_BUILD, debugMessage); Tracer.Fail(debugMessage); } return((int)processExitCode); }
/// <summary> /// Blocks until the command finishes executing /// </summary> /// <param name="fileName"></param> /// <param name="commandLine"></param> /// <param name="workingDirectory"></param> /// <returns></returns> public string VsExecCommand(string fileName, string arguments, string workingDirectory) { IVsLaunchPad lp = GetService(typeof(SVsLaunchPad)) as IVsLaunchPad; if (lp == null) { OutputGeneral("Failed to create launch pad"); return(null); } IVsOutputWindowPane owp = GetOutputWindowPaneGeneral(); if (owp == null) { OutputGeneral("Failed to get output window general pane"); return(null); } string commandLine; if (String.IsNullOrEmpty(arguments)) { commandLine = fileName; } else { StringBuilder sb = new StringBuilder(fileName); sb.Append(" ").Append(arguments); commandLine = sb.ToString(); } uint exitCode = 0; string[] output = new string[1]; int hr = lp.ExecCommand(fileName, commandLine, workingDirectory, (uint)_LAUNCHPAD_FLAGS.LPF_PipeStdoutToOutputWindow, owp, (uint)VSTASKCATEGORY.CAT_USER, 0, "", null, out exitCode, output); if (ErrorHandler.Failed(hr)) { OutputGeneral(fileName + " failed to launch: hr=0x" + hr.ToString("X8")); return(null); } OutputGeneral(fileName + " exited with exitCode " + exitCode); if (exitCode != 0) { return(null); } return(output[0]); }
/// <summary> /// Creates a new <see cref="IVsLaunchPad"/> object. /// </summary> /// <returns>A <see cref="IVsLaunchPad"/> object.</returns> private IVsLaunchPad CreateLaunchPad() { IVsLaunchPad launchPad = null; // Get a IVsLaunchPadFactory from the environment to use in creating our IVsLaunchPad. IVsLaunchPadFactory launchPadFactory = (IVsLaunchPadFactory)Package.Instance.Context.ServiceProvider.GetService(typeof(IVsLaunchPadFactory)); if (launchPadFactory != null) { int hr = launchPadFactory.CreateLaunchPad(out launchPad); NativeMethods.ThrowOnFailure(hr); } return(launchPad); }
//========================================================================================== // Methods //========================================================================================== /// <summary> /// Executes the command line, piping output to the specified output pane. /// </summary> /// <param name="outputPane">The output pane to write message to.</param> /// <param name="launchPadEvents">Receives event callbacks on the progress of the process.</param> /// <returns>Value returned by the process.</returns> public int ExecuteCommand(IVsOutputWindowPane outputPane, IVsLaunchPadEvents launchPadEvents) { Tracer.VerifyNonNullArgument(outputPane, "outputPane"); Tracer.VerifyNonNullArgument(launchPadEvents, "launchPadEvents"); // Create the IVsLaunchPad object if it hasn't been created yet. if (this.launchPad == null) { this.launchPad = this.CreateLaunchPad(); } uint processExitCode; uint flags = unchecked((uint)this.Flags); uint taskPadCategory = unchecked((uint)this.TaskPadCategory); uint taskItemBitmap = unchecked((uint)this.TaskItemBitmap); int hr = this.launchPad.ExecCommand(null, this.CommandLine, this.WorkingDirectory, flags, outputPane, taskPadCategory, taskItemBitmap, null, launchPadEvents, out processExitCode, null); if (NativeMethods.Failed(hr)) { string debugMessage = PackageUtility.SafeStringFormatInvariant("Error in attempting to launch command '{0}': Hr=0x{1:x}", this.CommandLine, hr); Package.Instance.Context.NotifyInternalError(ResourceId.IDS_E_BUILD, debugMessage); Tracer.Fail(debugMessage); } return (int)processExitCode; }