1

Is there an equivalent to iwr https://deno.land/install.ps1 -useb | iex for .bat files? I would like to run install-bin-windows.bat from https://yihui.org/tinytex/#installation without manually downloading and executing the file.

This is the error I got when I attempted to pipe the content of the .bat file to iex

PS C:\Users\shara> iwr https://tinytex.yihui.org/install-bin-windows.bat -useb | iex
Invoke-Expression:
Line |
   1 |  iwr https://tinytex.yihui.org/install-bin-windows.bat -useb | iex
     |                                                                ~~~
     | Missing opening '(' after keyword 'for'.
ducaale
  • 637
  • 6
  • 17
  • I believe you can just pipe the output directly to cmd.exe //// `Invoke-RestMethod https://tinytex.yihui.org/install-bin-windows.bat | cmd` – Daniel Aug 10 '22 at 22:06
  • 1
    @Daniel, that is tempting, but not robust: most notably, `for` loops and escaped `%` chars. malfunction with this approach, and there are other limitations. – mklement0 Aug 11 '22 at 14:28

1 Answers1

2

This answer explains that while you technically can pipe the content of a batch file directly to cmd.exe, the resulting limitations mostly make this impractical.

Thus, unfortunately, a robust solution requires saving the downloaded content to a temporary batch file and executing that, as also shown in the linked answer, via the custom
Invoke-AsBatchFile function.

mklement0
  • 382,024
  • 64
  • 607
  • 775