Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6576887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:02+00:00 2026-05-25T15:34:02+00:00

My ruby script gets certain inputs from command line arguments. It check if any

  • 0

My ruby script gets certain inputs from command line arguments. It check if any of the command line argument is missing, then it prompts for an input from user. But i am not able to get input from user using gets.

Sample code: test.rb

name=""
ARGV.each do|a|
    if a.include?('-n')
        name=a
        puts "Argument: #{a}"
    end
end
if name==""
    puts "enter name:"
    name=gets
    puts name
end

Running script: ruby test.rb raghav-k

Results in the error:

test.rb:6:in `gets': No such file or directory - raghav-k (Errno::ENOENT)
    from test.rb:6:in `gets'
    from test.rb:6:in `<main>'

Any pointers in this direction will be really grateful
Thanks
Sandy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:34:03+00:00Added an answer on May 25, 2026 at 3:34 pm

    gets will only read from the real $stdin (ie the user) if there are no command line arguments. Otherwise it’ll take those arguments as files to concatenate as a virtual $stdin.

    You can use STDIN.gets to make sure you’re always using the right function.

    You can also delete the arguments from ARGV as you go (or remove them all in one go), your gets should work correctly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want my Ruby Script File to run as executable from any directory of
I would like to install ruby from the command line. I don't mind where
I have a simple Ruby script that looks like this require 'csv' while line
How do I export an environment variable from within a Ruby script to the
I have a problem. I want to run a ruby script from another ruby
I was looking for a portable script or command line program that can synchronize
I have a ruby script below which infinitely prints numbers from 1 onward. How
I've made a ruby script that generate a Plist from data in other format
I'm trying to call a Ruby script from a bash script, but no luck.
I have written a ruby script which opens up dlink admin page in firefox

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.