Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

PShell and In-Process Pipes

Aug
2,799
144
From a freshly started stand-alone TCC 36.52.88 x64 in Windows 10 [Version 10.0.19045.7663]

Chomp is contained in my PowerShell 5.1 profile;

Code:
E:\Utils>pshell /s $Profile
C:\Users\jlcav\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Code:
R:\>pshell /s "get-content function:chomp"
    [CmdletBinding()]
    param(
        [Parameter(
            Position = 0,
            Mandatory = $true
        )]
        [ValidateRange(0, [int]::MaxValue)]
        [int] $Count,
        [Parameter(
            ValueFromPipeline = $true
        )]
        [AllowNull()]
        [object] $InputObject
    )
    process {
        if ($null -eq $InputObject) {
            return
        }
        $line = [string]$InputObject
        $line.Substring(0, [Math]::Min($Count, $line.Length))
    }

R:\>

Code:
R:\>*type lines.txt
Line1
Line2
Line3

Code:
R:\>*type lines.txt |! pshell /s "$s = [Console]::In.ReadToEnd(); $s -split '\r?\n' | chomp 4"
Line
Line
Line

R:\>*type lines.txt |! pshell /s "$s = [Console]::In.ReadToEnd(); $s -split '\r?\n' | chomp 4"
Line
Line
Line

R:\>*type lines.txt |! pshell /s "$s = [Console]::In.ReadToEnd(); $s -split '\r?\n' | chomp 4"
PSHELL: The handle is invalid.


R:\>*type lines.txt |! pshell /s "$s = [Console]::In.ReadToEnd(); $s -split '\r?\n' | chomp 4"
PSHELL: The handle is invalid.

R:\>*type lines.txt |! pshell /s "$s = [Console]::In.ReadToEnd(); $s -split '\r?\n' | chomp 4"

TCC 36.52.88 x64 hangs, and has to be closed via X in upper right corner.

Joe
 
For now,
my work around is to avoid the pipe completely,
and let PowerShell do everything itself.

Code:
R:\>pshell /s "$s = Get-Content -Raw r:\lines.txt; $s -split '\r?\n' | chomp 4"
Line
Line
Line

Joe
 
Back
Top