Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Ruby解包.tgz文件_Ruby_Linux - Fatal编程技术网

如何使用Ruby解包.tgz文件

如何使用Ruby解包.tgz文件,ruby,linux,Ruby,Linux,我需要的是解压缩以.tgz结尾的随机文件名 当我使用irb(通过命令行解释ruby)时,这个命令可以工作 `tar xzf *.tgz` 只要我在合适的目录中 但是,这在ruby脚本中不起作用。我使用 puts Dir.pwd Dir.chdir("unprocessed/") do puts Dir.pwd end `tar xzf *.tgz` 这将我放入未处理的子目录,然后我尝试运行上面的tar命令。 然而,它给了我这个错误,但同样的事情在irb中工作 tar (child):

我需要的是解压缩以.tgz结尾的随机文件名

当我使用irb(通过命令行解释ruby)时,这个命令可以工作

`tar xzf *.tgz`
只要我在合适的目录中

但是,这在ruby脚本中不起作用。我使用

puts Dir.pwd
Dir.chdir("unprocessed/") do
   puts Dir.pwd
end
`tar xzf *.tgz`
这将我放入未处理的子目录,然后我尝试运行上面的tar命令。 然而,它给了我这个错误,但同样的事情在irb中工作

tar (child): *.tgz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now
我需要的是解压缩以.tgz结尾的随机文件名 然后我会读到里面是什么

编辑---- 在公认答案的帮助下,我最终使用了

Dir.chdir("unprocessed/") do
    puts Dir.pwd
    `tar xzf #{Dir.pwd}/*.tgz`
end

backticks会引发一个对Dir.pwd一无所知的新shell,因此您需要的是如下内容:

Dir.chdir("unprocessed/") do
   `tar xzf #{Dir.pwd}*.tgz`
end

我不知道是它干的。谢谢
Dir.chdir("unprocessed/")
`tar xzf #{Dir.pwd}*.tgz`