Question Script causes Powershell to open in Console Host instead of Windows Terminal

Status
Not open for further replies.

kanishknishar

Distinguished
Jun 13, 2016
168
0
18,680
I am trying to run a script that opens a powershell instance for every sub-directory and runs the command whisperPath

Here's the code:

Code:
Get-ChildItem -Directory -Recurse | ForEach-Object { Start-Process -FilePath "pwsh.exe" -ArgumentList "-NoExit -Command Set-Location -LiteralPath '$($_.FullName)'; whisperPath" }

When I run the code on my desktop (also running Windows 10), each instance of Powershell opens in Windows Terminal successfully but that is not the case on my laptop which opens each Powershell window in Windows Console Host despite WT being the default terminal manager on my laptop:

User's image


When I type pwsh in address bar or start it from Windows Start Menu, it starts in Windows Terminal. I also opened pwsh's Properties which showed that using legacy mode was disabled.

PowerShell Environment Variables:

42b24886-51ad-4351-85ba-3fd5b6258e4e



About PC:

Device name Lance
Processor AMD Ryzen 5 5500U with Radeon Graphics 2.10 GHz
Installed RAM 16.0 GB (15.3 GB usable)
Device ID 9E*************************B1
Product ID 00*************************EM
System type 64-bit operating system, x64-based processor
Pen and touch No pen or touch input is available for this display

Edition Windows 10 Home
Version 22H2
Installed on ‎27-‎08-‎2023
OS build 19045.3448
Experience Windows Feature Experience Pack 1000.19044.1000.0
 

Ralston18

Titan
Moderator
Apologies: Compare rights between laptop and WT desktop

= = = =

Okay:

My next questions are about the Startup screen configuration/settings.

Why, for example, is WT not selected to launch when logging into Windows?

What is required to be shown when Terminal Starts?

New Instance behavior - what is required. [Side note: is there a limit on the number of instances?

Key is to find some difference between the "working" desktop and the "failing" laptop.

Details matter.
 

kanishknishar

Distinguished
Jun 13, 2016
168
0
18,680
Apologies: Compare rights between laptop and WT desktop

= = = =

Okay:

My next questions are about the Startup screen configuration/settings.

  1. Why, for example, is WT not selected to launch when logging into Windows?
  2. What is required to be shown when Terminal Starts?
  3. New Instance behavior - what is required. [Side note: is there a limit on the number of instances?

Key is to find some difference between the "working" desktop and the "failing" laptop.

Details matter.
1. Why would I want WT to start when launching Windows? It should start only when needed.
2. I don't understand what that means. That wouldn't matter to my script running properly, no?
3. The script which I've supplied opens a new instance of pwsh7 in WT for each sub-directory as current folder and run the wp command.

Settings on my laptop:

NrqaRvt.png


Settings on my desktop:

P90BpAP.png

EDIT: I updated my Desktop Windows Terminal too as it was an older version, re-ran the wpr command and it still worked fine.

To be extra-safe I copied my powershell profile once again so that the commands were the exact same and re-ran the command on my desktop. Yep each new instance of pwsh opened inside Terminal.
 
Last edited:

kanishknishar

Distinguished
Jun 13, 2016
168
0
18,680
My PowerShell scripts (wp = whisperPath and wpr = whisperPathRecursive):

Code:
function whisp([string]$file) {

    $fileName = "$(Split-Path (Split-Path $file -Parent) -Leaf)\$(Split-Path $file -Leaf)"
   
    Write-Output "Transcribing: $($fileName) at $(Get-Date -Format 'dd/MM/yyyy HH:mm:ss')"
    whisper --model small.en --fp16 False --output_format "srt" "$file"
    Write-Output "Finished Transcribing: $($fileName) at $(Get-Date)`n-------------------------------"

}

function whisperPath () {

    Get-ChildItem *.mkv, *.mp4, *.ts, *.flac, *.m4a, *.ogg, *.opus, *.mp3 | ForEach-Object {
        & whisp($_.FullName);
    }

}

function whisperPathRecursive () {
   
    Get-ChildItem -Directory -Recurse | ForEach-Object { Start-Process -FilePath "pwsh.exe" -ArgumentList "-NoExit -Command Set-Location -LiteralPath '$($_.FullName)'; whisperPath" }
}

Set-Alias -Name wp -Value whisperPath
Set-Alias -Name wpr -Value whisperPathRecursive
 
Last edited:

Ralston18

Titan
Moderator
Very good.

I understand that it is frustrating but the objective is to discover some difference between the desktop and laptop.

And you are a step ahead with regards to looking at Windows Terminal versions.

The problem at hand [full disclosure] is one of those problem posts (one of many :) ) where the answer is not something I know directly.

What I do know is that something is different and that I need to work through a troubleshooting process to methodically narrow down possible culprits.

What about:

"When I run the code on my desktop (also running Windows 10), each instance of Powershell opens in Windows Terminal successfully but that is not the case on my laptop which opens each Powershell window in Windows Console Host despite WT being the default terminal manager on my laptop:"

So the question (in my mind) is what is causing Windows Console Host to open instead of WT?

I found the following link:

https://www.anoopcnair.com/windows-terminal-default-command-line-app/

Look at Option 1 in the link.

On my system the Terminal configuration is "Let Windows decide".

Look /compare the Terminal configuration on both the desktop and laptop.

Noted that Windows Terminal includes the line Microsoft Corporation |1.17.11461.0

Your desktop and laptop are different. Your desktop matches my desktop. Laptop being different.

See where that leads....
 

kanishknishar

Distinguished
Jun 13, 2016
168
0
18,680
On my system the Terminal configuration is "Let Windows decide".

Look /compare the Terminal configuration on both the desktop and laptop.
WT has been set as default on both.

Noted that Windows Terminal includes the line Microsoft Corporation |1.17.11461.0

Your desktop and laptop are different. Your desktop matches my desktop. Laptop being different.
You just need to check for updates. That's what I did on my Desktop to make the laptop and desktop version be latest.

_____

I reinstalled Windows Terminal, copy-pasted the settings.json file from my desktop (just for safety) and now it works. Who knows what exactly was causing the issue. It's fixed now though.
 
Status
Not open for further replies.