如何在不在末尾附加新行的情况下在 Powershell 中写入 Netcat 输出?

How can I write to Netcat output in Powershell without a new line being appended to the end?

我正在尝试使用 Powershell 中的 Write-Output 命令向 Netcat 写入一行,但如果不发送新行我似乎无法执行此操作。到目前为止我已经试过了...

Write-Output "command" | nc -w1 aa.bb.cc.dd xxxx

"command" | nc -w1 aa.bb.cc.dd xxxx

...但是两者都会导致新行与 "command" 一起发送。有人可以帮我找到类似于 Linux 中的 Write-Host -NoNewLine 或 Echo -n 的解决方案吗?

取自Can I send some text to the STDIN of an active process under Windows?

$psi = New-Object System.Diagnostics.ProcessStartInfo;

$psi.FileName = "ncat.exe"
$psi.UseShellExecute = $false
$psi.RedirectStandardInput = $true

$psi.Arguments = 'localhost','9990'    #ncat connection args
$psi.CreateNoWindow = $true

$p = [System.Diagnostics.Process]::Start($psi)

Start-Sleep -s 2

$p.StandardInput.Write("command") #StandardInput is a StreamWriter 
$p.StandardInput.Write("command") 
$p.Close()