Skip to main content

All Questions

Tagged with
1 vote
1 answer
136 views

Ruby: "Parasite" characters with gets after pressing arrow key on getch

I've been looking into a way to implement a "Press any key to continue" feature into my program, and figured I'd use $stdin.getch. Seems to work in most cases, but I noticed that if I ...
Qwib's user avatar
  • 13
1 vote
1 answer
117 views

Palindromic Prime numbers array creator [Speed Issues] RUBY

I want to create an array of palindromic prime numbers nth numbers. I wrote the code below: # Enter your code here. Read input from STDIN. Print output to STDOUT require 'prime' number = gets ...
naarter's user avatar
  • 41
1 vote
1 answer
228 views

Ruby treats first command-line args as stdin

Running a Ruby script with command line args make $stdin read from the first command-line arg instead of from a tty. echo "puts gets" > myscript.rb ruby myscript.rb foo # myscript.rb:1:in ...
Jellicle's user avatar
  • 29.7k
-1 votes
1 answer
939 views

How to use stdin and stdout in Ruby

So I have a following method which works, without the use of stdin or stdout. def main(lines) lines.each_index do |i| word = lines[i] if word.length > 1 && word.length <=11 ...
Ryo Fujiwara's user avatar
0 votes
2 answers
274 views

remove and replace the text when putting a string into the console $stdin ruby

I have a program that is a client, talking to a server with socket. When the user is inputting a message, if another message comes in, it breaks up the text visually, making it hard to understand for ...
LonelyLittleLucas's user avatar
0 votes
1 answer
405 views

Both get STDOUT in realtime and provide STDIN

I have a command that requires I give it some STDIN data, as in my-command <<< my-data. I don’t have control over the command; the info is meant to be given interactively and <<< ...
user137369's user avatar
  • 5,574
0 votes
1 answer
227 views

How to read a really long string from STDIN in ruby?

I've been using STDIN.gets read strings from stdin in ruby, but I just noticed that these strings must be shorter than 1024 characters. None of the following methods will read strings longer than 1024 ...
andersonvom's user avatar
  • 11.8k
1 vote
0 answers
75 views

Ruby wrapper (open3) - how to capture live user input while script is in progress?

I'm trying to write a wrapper script to tie together the function of 4 related scripts. Normally we have to run these 4 scripts in order to achieve a certain state, but I would like to wrap these 4 ...
lowly_junior_sysadmin's user avatar
4 votes
2 answers
2k views

How to capture some special key presses for Ruby input prompt in Terminal (and let others through normally)

I am in a Ruby script something like: something = gets # or STDIN.gets puts something def arrow_pressed puts "arrow totally pressed" end Once the user prompt exists I want all keyboard ...
PlacateTheCattin's user avatar
1 vote
1 answer
221 views

Thread ignoring first input when using getch

require 'rubygems' require 'mechanize' require 'io/console' flag = 0 t2 =Thread.new do puts flag loop do temp = STDIN.getch if temp=="\n" flag = (flag+1)%2 ...
Rishav's user avatar
  • 3,978
-1 votes
1 answer
69 views

Ruby Is it possible to create hash in array with space character?

With STDIN, I want to create hash in array only by a space character. My ideal is $ Bob 90 # => [{"Bob" => 90}] But my code in ruby file is array = [] name = gets.chomp score = ...
BRYAN_JP's user avatar
0 votes
1 answer
84 views

Using STDIN in ruby , how to print out the multiline comments without REGEX

Given STDIN with the following: =begin This is a multiline comment and con spwan as many lines as you like. But =begin and =end should come in the first line only. =end Without using regex , how ...
jeancode's user avatar
  • 6,115
0 votes
0 answers
286 views

Ruby - STDIN with getc()

I am trying save the input from the command prompt into an array. The input will be integers and the first number will be the total number of characters that follow. An example input would look like: ...
Abram's user avatar
  • 59
0 votes
2 answers
458 views

Forwarding stdin to a subprocess in Ruby on Windows

I am developing a wrapper for Terraform, which at some point during its execution, it may request user input. So, my application must forward everything typed on its stdin to the subprocess' stdin. ...
betabandido's user avatar
  • 19.5k
0 votes
0 answers
32 views

gets not working for large strings in ruby [duplicate]

I am doing some coding on online coding platforms. While taking a large string a input from STDIN I am using gets but I am getting only a string of length max 1024. any suggestion for better way to ...
ritzz.soni's user avatar

15 30 50 per page
1
2 3 4 5
7