Why can't I run an .exe file (from ISE) which requires response from a user?

Hi,

I’m trying to run tex.exe from Powershell ISE, but it hangs after the banner (of tex.exe) is displayed. This is when tex.exe asks for user input if run from cmd.exe. How do I run interactive (live) .exe files from Powershell ISE?

Keeping the issue a side, Curious to know on why do you wan’t to execute this interactive exe from PowerShell ISE ?

You’re right. It doesn’t work with findstr either. (I pressed enter after control z.) You can use cmd, then run powershell inside it. I prefer it that way. Or Vscode.

PS C:\Users\admin> findstr hi
hi there
^Z
hi there

In the ISE, you must pass the full command and any params.

The ISE script pane and the console, is not a real console like the console host. It’s more of a output windows with some interactive capabilities.

The ISE console or script pane are not to be used for external user interactive .exe, that is by design and documented as such.

Differences between the ISE and PowerShell console
https://devblogs.microsoft.com/powershell/differences-between-the-ise-and-powershell-console

Console Application (Non) Support in the ISE
https://devblogs.microsoft.com/powershell/console-application-non-support-in-the-ise

If you want to do interactive stuff, use the console host, or use VSCode and the defined terminal of choice.

Again, you can call interactive use exe’s via the ISE, but you would need to shell out to the console host to use them or pass all you need when you run them from the ISE or the ISE console.

For example:

nslookup # will hang the ISE and you'd have to forcibly close it.

nslookup Microsoft.com # will not. You will get results

Even this, not all external DOS based commands are even allowed.

In PowerShell v3 and higher, the new PowerShell ISE script editor has improved a lot. Yet, it still has no real console but instead sports a useful console simulation. Some applications do require a real console, though. If you run those in PowerShell ISE, the editor may become unresponsive. Here is a sample that halts PowerShell ISE because choice.exe waits for input it never receives:

Choice.exe

To prevent this, PowerShell ISE maintains a list of unsupported console applications and won’t run them. The list is stored in the variable $psUnsupportedConsoleApplications (which does not exist in the regular PowerShell console).

$psUnsupportedConsoleApplications

# Results
wmic
wmic.exe
cmd
cmd.exe
diskpart
diskpart.exe
edit.com
netsh
netsh.exe
nslookup
nslookup.exe
powershell
powershell.exe 

You can improve this list and add applications that you find won’t run well in PowerShell ISE. For example, you could add choice.exe to the list:

$psUnsupportedConsoleApplications.Add('choice.exe')
choice.exe

Cannot start “choice.exe”. Interactive console applications are not supported. To run the application, use the Start-Process cmdlet or use “Start PowerShell.exe” from the File menu. To view/modify the list of blocked console applications, use $psUnsupportedConsoleApplications, or consult online help.

To execute your exe, from the ISE script pane or ISE console, you have to do something like this…

$ConsoleCommand = 'whatever exe you want to use and all its params / switches'
Start-Process powershell -ArgumentList "-NoExit","-Command  &{ $ConsoleCommand }" -Wait}

This shells out to the console host, runs the commands, waits so you can see results, then you can close and go back to the ISE.

I wrote a function I pulled together that I keep available for these exact scenarios. That way I call my function, pass it my external exe command string and it runs as expected.

See also:

PowerShell: Running Executables
https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx

Calling native commands from PowerShell
https://www.powershellmagazine.com/2013/01/02/calling-native-commands-from-powershell

postanote, thank you very much for the helpful and extensive explanation. It all makes sense now.

No worries.
I come across folks, taken aback by this a lot when deal with customers and there admins in teaching sessions, and normal enterprise work.