Converting an ncat command on Windows from a Mac/Nix example

I'm working with the Google Healthcare API and there's a step in the walk through that uses netcat to send an HL7 message to the MLLP adapter.

(I used nmap to download ncat for Windows)

I have the adapter running locally but the command they provide is written for Mac/Nix users and I'm on Windows.

echo -n -e "\x0b$(cat hl7.txt)\x1c\x0d" | nc -q1 localhost 2575 | less

So I tried rewriting this for windows powershell:

$hl7 = type hl7.txt
Write-Output "-n -e \x0b" $hl7 "\x1c\x0d" | ncat -q1 localhost 2575 | less

When I try this, I get an error that "less" is invalid and also -q1 is also an invalid command.

If I remove -q1 and | less the command executes with no output or error message.

I'm wondering if I'm using ncat incorrectly here or the write-output incorrectly?

What is the -q1 parameter?

It doesn't seem to be a valid ncat parameter from what I've researched.

I've been following this walkthrough: https://cloud.google.com/healthcare/docs/how-tos/mllp-adapter#connection_refused_error_when_running_locally

1 answer

  • answered 2020-05-22 21:36 js2010

    We're really converting the echo command, not the ncat command. The syntax for ascii codes is different in powershell.

    [char]0x0b + (get-content hl7.txt) + [char]0x1c + [char]0x0d | 
      ncat -q1 localhost 2575 
    

    in ascii: 0b vertical tab, 1c file seperator, 0d carriage return http://www.asciitable.com

    Or this. `v is 0b and `r is 0d

    "`v$(get-content hl7.txt)`u{1c}`r" | ncat -q1 localhost 2575 
    

    If you want it this way, it's the same thing. All three ways end up being the same.

    "`u{0b}$(get-content hl7.txt)`u{1c}`u{0d}" | ncat -q1 localhost 2575 
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum