I have a ruby program that accepts files as input. I am trying to test that this functionality works by piping a file into the program by entering
cat file1.txt | ./app.rb
However, when I do this I get -bash: ./app.rb: Permission denied
I have tried using sudo cat file1.txt | ./app.rb
which prompts me for my password and then it appears nothing happens.
This works fine when I instead type
ruby app.rb file1.txt
Does anyone have any tips for how to get this to work?
As pointed out in the comments, I need to be able to read a file path from stdin AND pass them as parameters:
In my code I have this:
def input
if ARGV.length.positive?
ARGV
else
gets.chomp.split(' ')
end
end
I expect input
to return an array of file paths.