microsoft / Microsoft-Win32-Content-Prep-Tool

A tool to wrap Win32 App and then it can be uploaded to Intune
989 stars 209 forks source link

Crash If Output is Being Redirected #5

Closed felixstorm closed 3 years ago

felixstorm commented 5 years ago

The tool crashes if the output is being redirected. Output of IntuneWinAppUtil -c SomeSample -s Setup.exe -o . -q > test.log:

Unhandled Exception: System.IO.IOException: The handle is invalid.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Console.set_CursorVisible(Boolean value)
   at Microsoft.Management.Service.IntuneWinAppUtil.Program.Main(String[] args)

This is problematic if the tool is being included in automatic (CI) systems when there is no way for the output to be captured (especially in conjunction with https://github.com/microsoft/Microsoft-Win32-Content-Prep-Tool/issues/4)

iainbrighton commented 5 years ago

I have big problems running this from PowerShell too. It looks like writing the progress bar causes more problems than it solves 😢. Can the progress bar be disabled when running non-interactively, i.e. when using the -q switch?

wiseleaf23 commented 5 years ago

I too am having the same issues. This is integrated in a script but returns this error. Just launching it in its own window without parameters works fine, but that is not the reason that I am scripting :)

ctolkien commented 5 years ago

Running this in Azure DevOps, we're hitting a similar/the same issue:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Management.Service.IntuneWinAppUtil.LogUtil' threw an exception. ---> 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 System.Console.get_BufferWidth() |  
  | at Microsoft.Management.Service.IntuneWinAppUtil.LogUtil..cctor() |  
  | --- End of inner exception stack trace --- |  
  | at Microsoft.Management.Service.IntuneWinAppUtil.LogUtil.WriteLineForError(Object error) |  
  | at Microsoft.Management.Service.IntuneWinAppUtil.Program.Main(String[] args)
wiseleaf23 commented 5 years ago

I use this workaround by running it in its own PowerShell console :

$Command = "$WorkingDir\$IntuneWinAppUtil -c `"$SourceFolder`" -s `"$SourceFileName`" -o $WorkingDir -q"
$Bytes = [System.Text.Encoding]::Unicode.GetBytes($Command)
$EncodedCommand =[Convert]::ToBase64String($Bytes)
Start-Process PowerShell.exe -ArgumentList "-EncodedCommand $EncodedCommand" -Wait
felixstorm commented 5 years ago

Calling the tool using

Start-Process -Wait $intunewinapputil "-q -c `"$sourceFolder`" -s `"$itwSetupFile`" -o `"$outputFolder`""

also seems to work for us (it will also open a new console without output redirection).

wiseleaf23 commented 4 years ago

Might be fixed with the latest release?

Fixed the ArgumentOutOfRangeException error when running the tool in Windows Terminal.

Issue: https://github.com/microsoft/Microsoft-Win32-Content-Prep-Tool/issues/29

felixstorm commented 4 years ago

@wiseleaf23 No, unfortunately the error is still the same, even with the latest release (1.8). A problem has been fixed for Windows Terminal, but output redirection does still not seem to work.

mintsoft commented 4 years ago

This seems to be a problem in general if you run this through powershell. For example we have Execute.ps1 that does:

& "$PSScriptRoot\..\..\tools\Microsoft-Win32-Content-Prep-Tool-1.8.1\IntuneWinAppUtil.exe" -c "$tmp\in" -s "installer.msi" -o "$tmp\out" -q

And it blows up with:

Unhandled Exception: System.TypeInitializationException: The type initializer for 'Microsoft.Management.Service.IntuneWinAppUtil.LogUtil' threw an exception. ---> System.IO.IOException: The handle is invalid.

   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.Console.SetBufferSize(Int32 width, Int32 height)
   at System.Console.set_BufferHeight(Int32 value)
   at Microsoft.Management.Service.IntuneWinAppUtil.LogUtil..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Management.Service.IntuneWinAppUtil.LogUtil.WriteLineForError(Object error)
   at Microsoft.Management.Service.IntuneWinAppUtil.Program.Main(String[] args)

Even under 1.8.1

:(

jonatanhost commented 3 years ago

Are there any workaround for this? I have tried the ones listed above but does not work in an Azure Function environment.

mintsoft commented 3 years ago

@jonatanhost we run it in cmd and the problem isn't there

coaqii commented 3 years ago

Does anyone have a workaround for this?

I have also tried the ones listed above but it does not work in an Azure Function environment.

@nikyusof ?

onerstam commented 3 years ago

Cross reference: https://developercommunity.visualstudio.com/content/problem/1269111/failure-to-run-intunewinapputilexe-on-hosted-devop.html