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 6704427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:17:15+00:00 2026-05-26T07:17:15+00:00

The intended operation of the Ruby code below is as follows: write ARGV[0], a

  • 0

The intended operation of the Ruby code below is as follows:

  1. write ARGV[0], a file named on the command line, to old
  2. create a new, temporary copy of that file
  3. loop until user gives input
  4. remove the temporary file

When I hard code old equal to hello.c, Timeout inside the do loop works as I would expect: it waits for 3 seconds for input from the keyboard, if none is given enter the rescue block and repeat.

When I set old equal to ARGV[0] (which is also hello.c), fp is assigned the first line of hello.c and the code breaks out of the loop.

How I run it:

user@cpu live$ ruby test.rb hello.c 
hello.c
#include <stdio.h>
user@cpu live$

The code:

#!/usr/bin/env ruby

require 'timeout'

old = ARGV[0].chomp
puts old  # sanity check
# old = 'hello.c'
new = 'tmp_' + old
`cp #{old} #{new}`

fp = nil
loop do
  begin
    Timeout::timeout(3) { fp = gets }
    puts fp  # sanity check
    break if (fp)
  rescue Timeout::Error
    # ...
  end
end

`rm #{new}`

I don’t understand why reading from the command line would be any different than hard coding the file name.

I appreciate any help you can give. Thanks.

  • 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-26T07:17:16+00:00Added an answer on May 26, 2026 at 7:17 am

    Check the docs:

    If Kernel.gets sees that ARGV is set, it uses them as filenames to
    feed instead of reading from stdin. So use an expicit: $stdin.gets

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

Sidebar

Related Questions

I intended to create a class which only have static members and static functions.
This code is intended to grab the ID of the deleted record, the user
I have the following class which is intended to return the subject line of
The sample method below is intended to detect whether or not it has been
I am writing a deferred task which is intended to construct a file in
I'm new to Django and trying to understand the preferred means of operation when
I have the following code, intended to log the event when a user closes
I have Python 2.6 on MacOS X and a multithread operation. Following test code
I intended for this function to call my MVC action method that returns a
What is the intended use of the optional else clause of the try statement?

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.