3

I am trying to pipe some commands via echo to plink over serial comport to a linux device. Most short commands work, but when I combined with a linux command that needs a pipe character "|" it breaks. Which makes sense, since cmd or echo thinks its a cmd commands it is trying to pipe to. I tried using "^|" to escape the pipe character but its not working.

I tried:

echo ble_util | head -n 10 | plink -serial COM17 -sercfg 115200
'head' is not recognized as an internal or external command,
operable program or batch file.

Again, makes sense since cmd thinks I am trying to pipe into head...but then I try:

echo ble_util ^| head -n 10 | plink -serial COM17 -sercfg 115200
'head' is not recognized as an internal or external command,
operable program or batch file.

Same issue, only difference is that the control is not returned to cmd, I have to ctrl+c to be able to gain back control.

Then I tried:

echo ble_util ^| head -n 10 ^| plink -serial COM17 -sercfg 115200
ble_util | head -n 10 | plink -serial COM17 -sercfg 115200

And obviously that works.

Any ideas?

Thanks in advance!

mwcmwc
  • 39
  • 3
  • Did you try replacing cmd `echo` with PowerShell `echo`? `powershell -command "echo 'echo aaa | grep aaa'" | plink ...`? – Martin Prikryl May 21 '19 at 11:10
  • 1
    Your 1st and 2nd example should behave differently. You might try `echo ble_util ^^^| head -n 10 | plink -serial COM17 -sercfg 115200` –  May 21 '19 at 11:11
  • @LotPings I can confirm the behavior the OP is seeing (on Windows 10). – Martin Prikryl May 21 '19 at 11:15
  • @MartinPrikryl With or without a head in my local path, with escaped `^|` I get a `'plink' is not recognized as an internal or external command`, so I'm a bit at a loss what's happening (WIn10Pro) –  May 21 '19 at 11:28
  • @LotPings It's processed from the end. So it first stops on `plink` (if you do not have it). But replace `plink` with anything you have (simple `echo`) and you will get an error on `head`. – Martin Prikryl May 21 '19 at 11:30
  • @MartinPrikryl You've got a point, but my double escaping seems to work because with `echo ble_util ^^^| head -n 10 | findstr "."` I get the whole piped string. –  May 21 '19 at 11:38
  • @LotPings Indeed, it might work. I was not objecting that :) – Martin Prikryl May 21 '19 at 11:40
  • Windows does not have a `head` command. What `head` are you using? – lit May 21 '19 at 12:46
  • 2
    @lit I believe, OP wants to send `ble_util | head -n 10` as a literal string/input to `plink` (to be executed on a connected Linux device). – Martin Prikryl May 21 '19 at 13:09
  • Hi all, sorry out sick yesterday. Will give the triple escape character a try and see what's going on. Any idea why I need to escape it that many times? Appreciate the help. – mwcmwc May 22 '19 at 12:27

0 Answers0