AtomicPorkchop
AtomicPorkchop

Reputation: 2675

Plink command is invalid to cmd.exe

I am trying to throw a plink command to my esx server and grep the linux output of the command. The code above does not work. But if I remove the | grep part it works again. Is there any other way to achieve the same results but making the command passable with cmd.exe?

FOR /F "TOKENS=1 DELIMS=:" %%A IN ('TYPE %SYSTEMDRIVE%\Users\Ian\Desktop\backup.list') DO ECHO %%A & (FOR /F "TOKENS=2*" %%B IN ('%PLINK% -batch -ssh %USERNAME%@%ESXHOST% -pw %PASSWORD% vim-cmd vmsvc/get.datastores %%A | grep datastore') DO ECHO %%B)

Upvotes: 2

Views: 496

Answers (1)

Kevin
Kevin

Reputation: 8561

Just looking at it (without plink.exe to test with at the moment), the problem seems to be that the | is being interpreted by cmd.exe instead of being passed as part of the argument string to plink.exe.

If that guess is correct, it's an easy fix: just escape the | by putting a ^ in front of it, so that %%A | grep becomes %%A ^| grep.

Upvotes: 1

Related Questions