PowerShell only communicates via text (strings) with external programs, it doesn't support raw byte streams; see this answer for more information.
In Windows PowerShell (but no longer in PowerShell (Core) 7+), curl
is a built-in alias for the Invoke-WebRequest
cmdlet; to call the external curl.exe
program instead, use curl.exe
, i.e. include the filename extension.
Since you do need raw byte-stream processing, use of the PowerShell pipeline isn't an option, but you can delegate to cmd.exe
:
# Make sure that the target dir. exists and get its full path.
# (If the target dir. doesn't exist, tar's -C option will fail.)
$targetDir = (New-Item -Force -ErrorAction Stop -Type Directory $HOME/tomcat-8.6.65).FullName
# Invoke cmd.exe's binary pipeline, passing the target dir.
# As an aside: tar.exe on Windows does NOT know that ~ refers to the
# user's home dir.
cmd /c @"
curl https://archive.apache.org/dist/tomcat/tomcat-8/v8.5.65/bin/apache-tomcat-8.5.65.tar.gz | tar xvz --strip-components=1 -f - -C "$targetDir"
"@
The above also corrects a syntax problem with your tar
command: -
should be -f -
.