我在 ruby 脚本中有类似以下内容的内容:
from = "/path/to/script.rb"
to = "/path/to/destination/"
puts "Copying #{from} to #{to}"
system("cp #{from} #{to}")
这会在终端中提供以下输出:
copying /path/to/script.rb
to /path/to/destination/
cp: missing destination file operand after ‘/path/to/script.rb’
Try 'cp --help' for more information.
我在终端中运行以下命令没有问题:
cp /path/to/script.rb /path/to/destination
也不在 ruby 脚本内:
system("cp /path/to/script.rb /path/to/destination")
任何关于如何更好地解决我的脚本问题的建议,或者正确方向的指针将不胜感激。
最佳答案
我正在从文件中读取内容,而不是修剪换行符。这应该从终端输出中显而易见(注意“to”之前的换行符和空格)。
更改自:
files = []
File.open(file-of-paths).read.each_line do |line|
files.push(line)
end
以下问题已解决:
files = []
File.open(file-of-paths).read.each_line do |line|
files.push(line.chomp)
end
关于ruby系统调用cp : missing destination file operand after,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26411424/