Sublime Forum

InputBox and PowerShell Build

#1

I’m using Sublime Text 3 Build 3083 on Windows 7 Professional, SP1, 64-bit.

If I attempt to use the “Build” functionality to run a PowerShell script that displays an InputBox, the InputBox is not displayed, the script does not finish, and the “powershell.exe” process is orphaned. This does not occur if I run the script outside of ST3 (e.g. via the Windows Explorer “Run with PowerShell” context menu, or via Windows PowerShell ISE), in which case the script functions exactly as expected. I am not very familiar with the “Build” functionality, but I am using what I assume to be the default Build System for PowerShell, as the “Tools -> Build System” option is set to “Automatic”, and the Syntax is “PowerShell”.

I have noticed that for some reason, if the script displays a MessageBox before attempting to display the InputBox, the issue does not occur, and the script runs as expected when executed via ST3 Build. This is merely a workaround, as I do not wish for my script to display an unnecessary MessageBox, but perhaps that info would be useful for debugging purposes.

The sample script below illustrates the issue. Is this something that can be fixed?

# load MessageBox assembly
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

# display MessageBox
# [System.Windows.Forms.MessageBox]::Show("MessageBox Text", "Text", 0, 64) | Out-Null  # Workaround: Uncomment this line

# load InputBox assembly
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null

# display InputBox
$input = [Microsoft.VisualBasic.Interaction]::InputBox("Enter some text:", "Enter Text", "Default text")

# output InputBox result
Write-Host $input
0 Likes

#2

I suspect this is because of how Sublime Text attempts to hide windows it spawns during the build process. This is mostly meant to hide the console that could be running in the background, but as a side effect it hides other GUIs as well.

I haven’t taken a deeper look as to how one could work around this

0 Likes

#3

Thanks for the reply.

I should have made this clearer in my original post, but ST3 has no problem displaying the MessageBox. So it seems to me it’s not so much a GUI issue in general, but rather something specific to the InputBox itself.

0 Likes