SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

Provide setting to not output to the console #5

Closed jclin closed 8 years ago

jclin commented 8 years ago

@SharpeRAD, sorry it's me again.

We encountered a scenario where scripts will fail when run under TeamCity because its cake/powershell runner does not have a console. In other words, Powershell will try to retrieve info from System.Console, but there is no window handle so an exception is thrown:

---> System.IO.IOException: The handle is invalid.
  at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
  at System.Console.GetBufferInfo(Boolean throwOnNoConsole, Boolean& succeeded)
  at Cake.Powershell.CakePSHostRawUserInterface.get_BufferSize()
  at System.Management.Automation.Internal.Host.InternalHostRawUserInterface.get_BufferSize()
  at Microsoft.PowerShell.Commands.OutStringCommand.InstantiateLineOutputInterface()
  at Microsoft.PowerShell.Commands.OutStringCommand.BeginProcessing()
  at System.Management.Automation.Cmdlet.DoBeginProcessing()
  at System.Management.Automation.CommandProcessorBase.DoBegin()
  --- End of inner exception stack trace ---
  at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
  at Cake.Powershell.PowershellRunner.Invoke(String script, PowershellSettings settings)
  at Submission#0.StartPowershellFile(FilePath path, PowershellSettings settings)
  at Submission#0.ExecutePowershellScriptFile(String scriptFileName, IList`1 arguments)

Admittedly, I don't know much about Managed Powershell; although this workaround fixed our issue, any suggestions for a cleaner solution are welcome.

SharpeRAD commented 8 years ago

Yea looks good, can't say no to that :+1: