1

I'm currently trying to run the following command in Windows Powershell:

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 - -C ~/tomcat-8.6.65

When I run this command it tries to untar the default value \\.\tape0 instead of the Tomcat tarball. I know that a workaround is to specify a filename with -f , however I don't know how that would be possible when I'm pulling the file from a URI. Does anyone have a solution to make this command work?

T. Douglass
  • 38
  • 1
  • 7

1 Answers1

1
  • 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 -.

mklement0
  • 382,024
  • 64
  • 607
  • 775
  • So I've rerun the command written as such, and I've even tried the original command in the command prompt, but I'm still getting the error of "Failed to open '\\.\tape0'". However, this time it's followed by a second error, "curl: (23) Failed writing body (0 != 16384). Does this coincide with the original issue or is this a separate matter? – T. Douglass Jun 29 '21 at 18:08
  • @T.Douglass: There were two problems, which the updated answer fixes: (a) The target directory passed to `-C` must already exist (and `tar.exe` does _not_ understand `~`) and (b) just `-` doesn't work, it must be `-f -`. – mklement0 Jun 29 '21 at 22:31