Reputation: 13
I am very new to ruby on rails and I have a very simple question. I am able to read the user input from a text field in ruby on rails
@user = params[:user]
I have to pass this value as an argument to a shell script I tried a number of things, but nothing works
run_command "./file.sh #{@user}"
and
%x(./file.sh #{@user})
The script receives "{user="
Any help is appreciated!
Upvotes: 0
Views: 151
Reputation: 487
First, make sure you escape any parameters you pass to command line. You may be easily attacked via command line injection this way. Try this instead:
system "/path/to/file.sh #{@user.shellescape}"
You may also want to try exec
, depending on how you want to track output. Please see http://ruby-doc.org/core-2.3.0/Kernel.html for more details on both
Upvotes: 1