Has anyone figured out how to write to and read Windows 11 Terminal?
Posted: Sat Aug 10, 2024 3:43 pm
In Windows 10 I could do this for PowerShell:
Now, that being said ... Windows 11 does have powershell installed and I have powershell 7 installed and the above works fine as it is. BUT! Since MS is moving towards a complete elimination of a separate powershell and command prompt and the functionality of these would be rolled into Windows Terminal in the future I'm kinda wondering how to start using Windows Terminal for the same functionality I get now from using the separate powershells.
Yes, you can run powershell code in Windows Terminal in Windows 11, the executable is called wt.exe. But whats its doing for right now is actually using powershell in the background. So I wanted to try using Windows Terminal to see if I can start modifying my code for my powershell stuff to use wt.exe and not powershell 5 or 7. So far I have not been successful - It runs wt.exe fine but there is never any return from Terminal and I'm not sure its even sending the code to terminal even with the #PB_Program_Write flag used (yes I tried various incarnations, and also using WriteProgramData,
WriteProgramString, WriteProgramStringN.
So what am I doing wrong - how is it done?
Code: Select all
; example version
; psrun$ = "pwsh.exe" ; for powershell 7
psrun$ = "powershell.exe" ; for native PS 5
a$ = " <some ps command code here>;"
b$ = " <some ps command code here>;"
c$ = " <some ps command code here - and what ever the return is>;"
cmdx$ = "$ErrorActionPreference = 'SilentlyContinue';" + a$ + b$ + c$ ; etc...
OutProg$ = ""
KeepOutProg$ = ""
ProgRun = RunProgram(psrun$, cmdx$,"", #PB_Program_Hide|#PB_Program_Open|#PB_Program_Read)
If ProgRun
While ProgramRunning(ProgRun)
OutProg$=ReadProgramString(ProgRun)
KeepOutProg$ = KeepOutProg$ + OutProg$
Wend
CloseProgram(ProgRun)
EndIf
ProcedureReturn = Trim(KeepOutProg$)
Yes, you can run powershell code in Windows Terminal in Windows 11, the executable is called wt.exe. But whats its doing for right now is actually using powershell in the background. So I wanted to try using Windows Terminal to see if I can start modifying my code for my powershell stuff to use wt.exe and not powershell 5 or 7. So far I have not been successful - It runs wt.exe fine but there is never any return from Terminal and I'm not sure its even sending the code to terminal even with the #PB_Program_Write flag used (yes I tried various incarnations, and also using WriteProgramData,
WriteProgramString, WriteProgramStringN.
So what am I doing wrong - how is it done?