0

I am trying to use the Write-Output command in Powershell to write a line to Netcat, but I cannot seem to do this without a new line being sent. So far I have tried...

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

and

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

... however both cause new lines to be sent along with "command". Can someone help me find a solution that would be similar to Write-Host -NoNewLine or Echo -n in Linux?

1 Answers1

0

Taking from 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()
Community
  • 1
  • 1
TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
  • Thanks for the response! Unfortunately I tried this and am still seeing a new line be sent. My second "command" is actually a "GET" which shows me the output of my previous command where an incorrect command will return the incorrect command that was previously entered. In my case this is the command with a new line appended to it. – user7147773 Nov 14 '16 at 22:09
  • @user7147773 open `ncat -l -k localhost 9990` in another window as a listener, and run this code, you'll see no newlines are being sent, both `commands` appear on the same line. And if you run it again the next commands appear on the same line as well. – TessellatingHeckler Nov 14 '16 at 23:39