shellcmdappcmd

Redirecting appcmd output to a variable


I am trying to run the following:

FOR /F "tokens=* delims=" %A IN ('C:\windows\system32\inetsrv\appcmd.exe list app /site.name:"car" /xml | C:\windows\system32\inetsrv\appcmd.exe list vdir /vdir.name:"car/" /text:physicalPath') DO SET Variable=%A

But get the following error:

| was unxepected at this time

Solution

  • If the data must be piped from a process to the other, you need to escape the pipe character. It should be ^|

    If what you need to do is execute both commands, replace the pipe character with ^&, the command concatenation operator, also escaped