문제

I am executing a ruby program on a series of files, using ARGV[0]. I would call my program as follows:

ruby specprep.rb '*.txt'

Within specprep.rb, I generate the list of files to be processed via the following:

require 'rake'
...    
@input_list = FileList.new("#{ARGV[0]}")

But later on, I want to call another ruby program that works in a similar way (i.e. that program also generates a list of files to be processed using ARGV). So I call my program, trying to pass it the ARGV[0] from the parent program (specprep.rb):

system("ruby absolute_directory_path/codenamer.rb #{ARGV[0]}")

but of course the shell has already expanded the ARGV[0] into a series of files, so now only the first file matching '*.txt' will be processed by codenamer.rb.

My question is: how can I pass the second program the same argument ('*.txt') that the first program took? I need an un-expanded version of that argument.

I have considered interpreting the Terminal history, but could not find a useful workaround. I have seen the Readline module but I could not incorporate that successfully to get the terminal history.

도움이 되었습니까?

해결책

Pass separate arguments to Kernel#system to avoid shell expansion:

system "ruby", "absolute_directory_path/codenamer.rb", ARGV[0]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top