3

I have recently started working with Kubernetes and Docker and still new with how it all works. I have made a ps1 script to run all the steps I need to do to build image and execute image on Kubernetes.

What I see is all steps work fine on ISE (except this one: "kubectl exec -it test-runner pwsh"). For this step alone, I have to run it on another PowerShell window.

When I run this step in ISE, the script keeps running without ever giving any error or stopping.

Does anyone know if its a limitation with Kubernetes working on ISE or if there is a workaround to make it work?

Working with ISE is quick and saves me tons of time, so this really makes a difference when I have to copy, paste, enter this each time in a separate PowerShell window.

Thanks in advance for your help!

P.S: I looked at other suggested similar questions/answers and none of them seem to be related to Kubernetes not working on ISE. Hence this question.

command:

kubectl exec -it test-runner pwsh

Expected (and actual when running from PowerShell console):

----------------------
PS C:\windows\system32> kubectl exec -it test-runner pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /test>
-----------------------------
Actual (when running from PowerShell ISE):

PS C:\SourceCodeTLM\Apollo>  kubectl exec -it test-runner pwsh
PowerShell 6.2.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

(with a blinking cursor and script running without breaking and changing to the new path)...
-----------------------------------------------
Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
Pramod Yadav
  • 467
  • 8
  • 14

3 Answers3

4

The PowerShell ISE doesn't support interactive console applications, which notably means that you cannot start other shells from it.

The ISE tries to anticipate that problem by refusing to start well-known shells. For instance, trying to start cmd.exe fails with the following error message:

Cannot start "cmd". Interactive console applications are not supported. 
To run the application, use the Start-Process cmdlet or use 
"Start PowerShell.exe" from the File menu.

Note:

However, it is impossible for the ISE to detect all cases where a given command (ultimately) invokes an interactive console application; when it doesn't, invocation of the command is attempted, resulting in obscure error messages or, as in your case, hangs.

As the error message shown for cmd.exe implies, you must run interactive console applications outside the ISE, in a regular console window.

From the ISE you can use Start-Process to launch a program in a new, regular console window; in the case at hand:

Start-Process kubectl 'exec -it test-runner pwsh'

Alternatively, run your PowerShell sessions outside the ISE to begin with, such as in a regular console window, Windows Terminal, or in Visual Studio Code's integrated terminal.

mklement0
  • 382,024
  • 64
  • 607
  • 775
0

After digging out, I found a way to interact with the interactive console applications.

we can use SendKeys('key_here') to specific application.

Faraaz Kurawle
  • 1,085
  • 6
  • 24
  • Note that this question is about the _fundamental inability_ to run interactive console applications _in the ISE_. You're answering a different question, namely _how to automate interacting_ with an interactive console application (which is better done via the pipeline / stdin rather than via simulated user actions, the latter being invariably brittle). – mklement0 Jan 16 '22 at 17:28
  • 1
    oh ok i misunderstood it, thanks for clarification. – Faraaz Kurawle Jan 16 '22 at 17:32
0

You could open a command window from PowerShell and send the command to open the shell.

Start-Process PowerShell -Wait "-NoProfile -ExecutionPolicy Bypass -Command `"kubectl exec helloworld-web-8495f4c888-jw2tg -n local-v1 -it -- /bin/bash`""
Karson
  • 449
  • 6
  • 11