Skip to content

STDIN Conflict #26

@kfries

Description

@kfries

Here is an example of my code that created a visual error, and the display to look funny. The progress bar still worked, and there is a work-around to stop the bug, but I thought I would mention it so that you can fix when you have the time...

q = Queue.new
ARGF.each_line do |line|
   (var1, var2) = line.split(",").map(&:chomp)
   q.push(MyClass.new(var1, var2)
end

bar = ProgressBar(q.size)
while not(q.empty?)
   ... do something
end

As you can see, I am reading a file from the command line, line by line, parsing it, and adding it to a queue. I am then using the ProgressBar to display processing of the data read. Now, ARGF allows me to provide files at the command line, or to pipe it to stdin. When I call my code as such:

$ cat datafile | myprogram.rb

It will display like so:

[root@dencts02 router-testing]# cat out.txt | ./check_routers
stty: standard input: Invalid argument
stty: standard input: Invalid argument 1/12] [  8.33%] [00:21] [03:58] [ 0.05/s]
stty: standard input: Invalid argument 2/12] [ 16.67%] [00:43] [03:37] [ 0.05/s]
stty: standard input: Invalid argument 3/12] [ 25.00%] [01:32] [04:38] [ 0.03/s]
stty: standard input: Invalid argument 4/12] [ 33.33%] [01:54] [03:48] [ 0.03/s]
stty: standard input: Invalid argument 5/12] [ 41.67%] [02:16] [03:10] [ 0.04/s]
stty: standard input: Invalid argument 6/12] [ 50.00%] [03:17] [03:17] [ 0.03/s]
stty: standard input: Invalid argument 7/12] [ 58.33%] [03:39] [02:36] [ 0.03/s]
stty: standard input: Invalid argument 8/12] [ 66.67%] [04:36] [02:18] [ 0.03/s]
stty: standard input: Invalid argument 9/12] [ 75.00%] [04:58] [01:39] [ 0.03/s]
stty: standard input: Invalid argument11/12] [ 91.67%] [05:04] [00:27] [ 0.04/s]
[##################################] [12/12] [100.00%] [05:28] [00:00] [ 0.04/s]

but if I call my program with a filename... then there is no problem:

$ myprogram.rb datafile
[#############################################] [12/12] [100.00%] [06:07] [00:00] [ 0.03/s]

It appears to get its knickers in a bunch if you are streaming in from STDIN.

Nice Gem, small minor non-critical bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions