Questions tagged [popen3]

Open3 grants you access to stdin, stdout, stderr and a thread to wait the child process when running another program.

Open3 grants you access to stdin, stdout, stderr and a thread to wait the child process when running another program

69 questions
24
votes
3 answers

How to retrieve exit status from ruby Open3.popen3()?

I seem to be stuck trying to retrieve the exit status of a shell command which was started from ruby's Open3.popen3()-method. Here's my code: require 'open3' stdin, stdout, stderr = Open3.popen3('ls') When I now try to access $? it still is nil…
Gerrit-K
  • 1,298
  • 2
  • 15
  • 30
15
votes
3 answers

How to fix hanging popen3 in Ruby?

I am getting unexpected behaviour using popen3, which I want to use to run a command like tool ala cmd < file1 > file2. The below example hangs, so that stdout done is never reached. Using other tools than cat may cause hanging, so that stdin done…
maasha
  • 1,926
  • 3
  • 25
  • 45
10
votes
1 answer

ruby popen3 -- how to repeatedly write to stdin & read stdout without re-opening process?

I am using Open3's popen3 method to start a process that functions in a console-like / REPL fashion to repeatedly accept input and return output. I am able to open the process, send input, and receive the output just fine, with code like…
Stu Blair
  • 1,323
  • 15
  • 24
9
votes
2 answers

Ruby—Open3.popen3 / how to print the output

I have a little ruby script which does a mysql import in the way: mysql -u -p -h < file.sql, but utilizes Open3.popen3 to do so. That is what I have so far: mysqlimp = "mysql -u #{mysqllocal['user']} " mysqlimp << "-h…
philipp
  • 15,947
  • 15
  • 61
  • 106
8
votes
2 answers

ruby open3 stdout and stdin how to interact

sum.rb is very simple. You input two numbers and it returns the sum. # sum.rb puts "Enter number A" a = gets.chomp puts "Enter number B" b = gets.chomp puts "sum is #{a.to_i + b.to_i}" robot.rb used Open3.popen3 to interact with sum.rb. Here's the…
mCY
  • 2,731
  • 7
  • 25
  • 43
7
votes
2 answers

Runy Open3.popen3 Entering input into the subprocess from the command-line

Goal: I am writing a workflow command-line program in ruby that sequentially executes other programs on the UNIX shell, some of which require the user to enter input. Problem: Although I can successfully handle the stdout and stderr thanks to this…
ImaginateWayne
  • 470
  • 1
  • 5
  • 14
7
votes
1 answer

Executing shell mail command using python

I have used the following code to send an email as suggested in one of the post on the similar topic. But the mail has not been sent. Any suggestions? import subprocess recipient = 'xxxxx@gmail.com' subject = 'test' body = 'testing mail through…
sandy
  • 181
  • 2
  • 3
  • 12
7
votes
1 answer

Kill a process called using open3 in ruby

I'm using a command line program, it works as mentioned below: $ ROUTE_TO_FOLDER/app < "long text" If "long text" is written using the parameters "app" needs, then it will fill a text file with results. If not, it will fill the text file with dots…
JavierQQ23
  • 704
  • 1
  • 8
  • 20
6
votes
0 answers

Closed stream (IOError) in ruby Open3.capture3 when using multithreading with timeout

I wish to run several system commands, and get the following: I wish to run each of the commands in different thread under the same process I wish to capture and store the output and exit status. I wish to set timeout on the execution time to find…
Noam Inbar
  • 133
  • 7
5
votes
2 answers

Scripting openssl to generate many certificates without manually entering password?

I have created a certificate authority and need to generate and sign 50+ certificates. I wanted to script this process. I don't want to have to manually enter a password 100+ times! Here is the command I was getting hung up on: openssl req -newkey…
Michael
  • 3,568
  • 3
  • 37
  • 50
4
votes
1 answer

Ruby: intercept popen system call and log stdout and stderr to same file

In ruby code I am running a system call with Open3.popen3 and using the resultant IO for stdout and stderr to do some log message formatting before writing to one log file. I was wondering what would be the best way to do this so log messages will…
Nick Hyland
  • 357
  • 1
  • 10
3
votes
1 answer

Perl: let open3 inherit STDIN, STDOUT, STDERR

This print 1..10 twice: seq 10 > /tmp/ten perl -e 'fork();seek(STDIN,0,0); print '
Ole Tange
  • 31,768
  • 5
  • 86
  • 104
3
votes
1 answer

Why does Open3.popen3 return wrong error when executable is missing?

I'm making a Ruby wrapper around a CLI. And I found a neat method, Open3.capture3 (which internally uses Open3.popen3), which lets me execute commands and captures stdout, stderr and exit code. One thing that I want to detect is if the CLI…
Janko
  • 8,985
  • 7
  • 34
  • 51
3
votes
3 answers

Start a child process in a different ruby version

I am using daemon kit to start a background ruby process that listens for Amazon SQS messages. Once a message is received then it starts an child process with Open3.popen3 that needs to run in JRuby. The background process needs to run in MRI since…
fedegl
  • 31
  • 3
3
votes
1 answer

Run `git add -p` from ruby

I am trying to run git add -p from ruby. The problem is that this command displays portions of files and waits for user input, potentially opening the git editor. The regular Kernel methods to execute system commands won't work for this reason. I…
Robert Audi
  • 8,019
  • 9
  • 45
  • 67
1
2 3 4 5