Powershell: Pipe external command output to another external command -
how can powershell understand type of thing:
robocopy.exe | find.exe "started"
the old command processor gave result, i'm confused how in powershell:
&robocopy | find.exe "started" #error &robocopy | find.exe @("started") #error &robocopy @("|", "find.exe","started") #error &robocopy | &find @("started") #error &(robocopy | find "started") #error
essentially want pipe output of 1 external command external command. in reality i'll calling flac.exe , piping lame.exe convert flac mp3.
cheers
tl;dr
robocopy.exe | find.exe '"started"' # note nested quoting.
for explanation of nested quoting, read on.
powershell does support piping , external programs.
the problem here 1 of parameter parsing , passing: find.exe
has curious requirement search term must enclosed in literal double quotes.
in cmd.exe
, simple double-quoting sufficient: find.exe "started"
by contrast, powershell default pre-parses parameters before passing them on , strips enclosing quotes, find.exe
sees started
, without double quotes, resulting in error.
there 2 ways solve this:
ps v3+ (only option if parameters literals and/or environment variables): special parameter
--%
tells powershell pass rest of command line as-is target program (reference environment variables, if any, cmd-style (%<var>%
)):
robocopy.exe | find.exe --% "started"
ps v2-, or if need use powershell variables in parameters: apply outer layer of powershell quoting (powershell strip single quotes , pass contents of string as-is
find.exe
, enclosing double quotes intact):
robocopy.exe | find.exe '"started"'
Comments
Post a Comment