Questions tagged [popen3]
Open3 grants you access to stdin, stdout, stderr and a thread to wait the child process when running another program.
                                	
	popen3
    
                            
                        
                    
            69
            questions
        
        
            24
            votes
        
        
            3
            answers
        
        
            13k
            views
        
    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('...
            
        
       
    
            15
            votes
        
        
            3
            answers
        
        
            9k
            views
        
    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 ...
            
        
       
    
            10
            votes
        
        
            1
            answer
        
        
            3k
            views
        
    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 ...
            
        
       
    
            9
            votes
        
        
            2
            answers
        
        
            12k
            views
        
    Ruby—Open3.popen3 / how to print the output
                I have a little ruby script which does a mysql import in the way: mysql -u <user> -p<pass> -h <host> <db> < file.sql, but utilizes Open3.popen3 to do so. That is what I have ...
            
        
       
    
            8
            votes
        
        
            2
            answers
        
        
            2k
            views
        
    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 ...
            
        
       
    
            7
            votes
        
        
            1
            answer
        
        
            10k
            views
        
    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 = '[email protected]'
...
            
        
       
    
            7
            votes
        
        
            1
            answer
        
        
            6k
            views
        
    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 ...
            
        
       
    
            7
            votes
        
        
            2
            answers
        
        
            2k
            views
        
    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 ...
            
        
       
    
            6
            votes
        
        
            0
            answers
        
        
            1k
            views
        
    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 ...
            
        
       
    
            5
            votes
        
        
            2
            answers
        
        
            7k
            views
        
    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 ...
            
        
       
    
            4
            votes
        
        
            1
            answer
        
        
            506
            views
        
    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 ...
            
        
       
    
            3
            votes
        
        
            1
            answer
        
        
            4k
            views
        
    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 ...
            
        
       
    
            3
            votes
        
        
            3
            answers
        
        
            4k
            views
        
    Python equivalent to find -exec
                I'm trying to run this BASH command in Popen:
find /tmp/mount -type f -name "*.rpmsave" -exec rm -f {} \;
But every time I get:
"find: missing argument to `-exec'\n" in stderr.
What would the ...
            
        
       
    
            3
            votes
        
        
            1
            answer
        
        
            446
            views
        
    Perl: let open3 inherit STDIN, STDOUT, STDERR
                This print 1..10 twice:
seq 10 > /tmp/ten
perl -e 'fork();seek(STDIN,0,0); print <STDIN>' </tmp/ten
I would like to do the same using IPC::Open3, but I cannot get that to work:
perl -...
            
        
       
    
            3
            votes
        
        
            1
            answer
        
        
            190
            views
        
    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 ...
            
        
       
    
            3
            votes
        
        
            3
            answers
        
        
            534
            views
        
    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.
...
            
        
       
    
            3
            votes
        
        
            2
            answers
        
        
            5k
            views
        
    Ruby Open3.popen3 simulate user input
                I am trying to run a bash script (@command) that requires user input and I'm trying to feed that script input using the following code:
Open3.popen3(@command) do |stdin, stdout, stderr|
  stdin.write(...
            
        
       
    
            3
            votes
        
        
            0
            answers
        
        
            1k
            views
        
    Using Ruby's popen3 or equivalent on Windows
                I'm making a Vim plugin that uses Open3.popen3 to run a shell command, and I need the result and exit code. It works fine on Linux, but freezes on Windows. I've checked on pry under Windows and ...
            
        
       
    
            2
            votes
        
        
            3
            answers
        
        
            4k
            views
        
    Use stderr in lua io.popen to determine faulty function call
                I'm making a function that can read the metadata of the current song playing in spotify. This is being programmed in lua since it is an implementation for awesome wm. I got the following line to get ...
            
        
       
    
            2
            votes
        
        
            2
            answers
        
        
            2k
            views
        
    Mocking popen3 block form ruby
                I am developing some test cases in Ruby using rspec.
I am attempting to mock the popen3 function.
However, while still keeping the blocking form, I am unable to capture the expected output ...
            
        
       
    
            2
            votes
        
        
            1
            answer
        
        
            63
            views
        
    Why does xelatex not want to be called by popen3 in vararg form?
                Take this minimal LaTeX document:
% minimal.tex
\documentclass{article}
\begin{document}
    Hello World!
\end{document}
And this Ruby (2.5.1) script:
require 'open3'
Open3.popen3(
  'xelatex', '-...
            
        
       
    
            2
            votes
        
        
            3
            answers
        
        
            2k
            views
        
    Open3.popen3 returns wrong error Errno::ENOENT on Windows
                I have the following code in test.rb:
require 'open3'
cmd = 'C:\Program Files\foo\bar.exe'
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
  puts "stdout: #{stdout.read}"
  puts "\n\n"
  puts "...
            
        
       
    
            2
            votes
        
        
            1
            answer
        
        
            675
            views
        
    IPC::Open3 run snmpwalk with different behavior than standalone snmwalk command
                I have made a custom sub to run various terminal-command in perl using Open3.
I encounter a strange problem with snmpwalk, when i run the command in terminal it work, but with Open3 it won't.
The sub ...
            
        
       
    
            1
            vote
        
        
            2
            answers
        
        
            2k
            views
        
    Ruby UTF-16 encoding I think
                I have a Ruby program  running on Windows which calls a shell command (which is known to output UTF-16) using Open3:
attrs={}
attrs[:stdout], attrs[:stderr], status = Open3.capture3(command)
unless ...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            691
            views
        
    Running multi-threaded Open3 call in Ruby
                I have a large loop where I'm trying to run the call to Open3.capture3 in threads instead of running linearly. Each thread should run independently and there's no deadlock in terms of accessing data.
...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            476
            views
        
    Ruby - Open3 popen3 function sanitized
                would like to run a system command on ruby using popen3 function from Open3. It would be something like:
pdf2htmlEX --zoom 1.3 ~/test.pdf
As the filename will be passed by params, I would like to ...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            310
            views
        
    Real-time output of a rake task with popen3
                It seems impossible to run a rake task from within a popen3 block while getting real-time output. All lines come at once at the end of the rake task. I'm trying to get real-time output from rake tasks ...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            573
            views
        
    Why is Ruby's popen3 crashing because "Too many files open"?
                I am using Popen3 to run some Perl scrips and then dump their output into a text file. Once in the text file, I search for the result of the Perl script. I get the error after running for about 40 ...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            105
            views
        
    Suppressing Command Prompt output while running a shell command in capture3
                I'm running Amazon's Kindle Previewer tool in a Ruby script through capture3. The Kindle Previewer command validates an epub file and prints a log to a specified folder, while also printing a log in ...
            
        
       
    
            1
            vote
        
        
            0
            answers
        
        
            338
            views
        
    Ruby deadlock waiting on Process::Waiter with Open3.popen3
                I was using Open3.capture3 in my ruby code and started to notice deadlocks. I did some research and came across this great blog about how open3 can cause deadlocks. Taking this into account I came up ...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            186
            views
        
    Track progress of dd command called using open3 in ruby
                I am trying to monitor the progress of copying a raspberry-pi OS image to a microSD card. This is similar to Kill a process called using open3 in ruby, except I'm not killing the process, I'm sending ...
            
        
       
    
            1
            vote
        
        
            0
            answers
        
        
            312
            views
        
    Ruby popen3 - How to prevent that repeatedly writing to stdin results in a timeout?
                Currently I'm writing to stdin in a loop when stdout provides me with the last line marker "EE\n". Now it should go on until the loop is terminated but for some reason stdout is not providing any new ...
            
        
       
    
            1
            vote
        
        
            0
            answers
        
        
            246
            views
        
    node-sass module install script does not exit when npm install is launched by Ruby's popen3
                UPDATE 3: This problem appears to be a part of the module installation of node-sass. The stranded process has a working directory of ./node_modules/node-sass, and its command-line scripts/install.js ...
            
        
       
    
            1
            vote
        
        
            0
            answers
        
        
            40
            views
        
    Passing next argument to 'STDIN'
                I am using open3 to pass STDIN to a program, and then read and parse STDOUT. My program expects an argument in the form of e0, e1 e2, etc.
Everytime a new argument is given, the STDOUT changes. I don'...
            
        
       
    
            1
            vote
        
        
            2
            answers
        
        
            832
            views
        
    How do I get the output (STDOUT) from Cucumber::CLI::Main.execute into a variable
                Running a cucumber script in Jruby 9.1.7.0. The output goes to STDOUT. How can I get it to save it into a local variable ?
require 'cucumber'
require 'stringio'
@output = StringIO.new
features = '...
            
        
       
    
            1
            vote
        
        
            0
            answers
        
        
            139
            views
        
    How to accept input with Open3.popen2e in Ruby
                I made a wrapper in Ruby that does a bunch of stuff, sets environmental variables, then executes an external program using the Open3 library, passing arguments (and ENV) to the external process.
...
            
        
       
    
            1
            vote
        
        
            0
            answers
        
        
            183
            views
        
    Open3.capture3 hangs without any outputs [duplicate]
                I have some codes like this in pry:
[1] pry(main)> require 'open3'
=> true
[2] pry(main)> output, error, status = Open3.capture3("multichain-util create testchain")
=> ["MultiChain ...
            
        
       
    
            1
            vote
        
        
            1
            answer
        
        
            241
            views
        
    How to avoid consecutive instantiation of Ruby Thread object in this code?
                I never used Thread till now, but I think I must rely on it in this case. I would like to process the stdout and the stderr of a cURL command line separately, because I want to exchange the carriage ...
            
        
       
    
            0
            votes
        
        
            3
            answers
        
        
            1k
            views
        
    How to return a dictionary as a function's return value running as a subprocess to its parent process?
                I have two scripts parent.py and child.py The parent.py calls child.py as a subprocess. Child.py has a function that collects certain result in a dictionary and i wish to return that dictionary back ...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            626
            views
        
    Ruby prevent command injection with open3
                in one of the project I am working with, we were using backtip approach to run system commands.
resp = `7z x #{zip_file_path} -p#{password} -o#{output_path}`
which works fine. But since it might lead ...
            
        
       
    
            0
            votes
        
        
            3
            answers
        
        
            314
            views
        
    Ruby run external program stops script
                I have a ruby script that midway through I need it to run another program.
After running the program the rest of the script doesnt get run. For example:
# some ruby that gets run
exe = "Something....
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            257
            views
        
    Python code to Perl
                I have a piece of python code, that I need to convert it to perl, but unfortunately I am not good in perl, so sorry if the question is simple.
I would like to check STDOUT and STDERR for a specific ...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            116
            views
        
    How to configure rubymine for use with open3?
                Issue
I am using xray-rails gem in a rails app and want it to open rubymine to the correct file when I click it in the browser.  It was unclear how to configure this.  xray-rails gem uses open3 to ...
            
        
       
    
            0
            votes
        
        
            2
            answers
        
        
            2k
            views
        
    Running cmd commands through ruby
                I am writing a program which execute an other program written in c, here is my first try
require 'Open3'
system 'tcc temp.c'
Open3.popen3('temp.exe') do |stdin, stdout, stderr|
   stdin.puts '21\n'
...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            901
            views
        
    trying to check if command exists with ruby popen3
                I am trying to check if system command exists with following code:
require 'open3'
Open3.popen3('non-existing command') do |stdin, stdout, stderr, thread|
  exit_error = stderr.readlines
  if ...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            405
            views
        
    Execute rake task in another project
                On the same machine I have two rails projects/servers.
From the one server I need to execute a rake task from the other project. This means to switch the context and the rake task to be run in the ...
            
        
       
    
            0
            votes
        
        
            2
            answers
        
        
            240
            views
        
    How to call function from shell script from ruby
                How to call function in shell script from ruby (preferably using open3)
#!/bin/sh
# A simple script with a function...
function add()
{
  echo "1"
}
Ruby Script that does not work--
#!/apollo/bin/...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            134
            views
        
    Executing the top command using Open3 in ruby
                I am trying to execute the "top -n 1" command in ruby using the Open3 module in ruby. 
This is my code 
command = "top -n 1"
Open3.popen3 (command) do |i,o,e,t|
        i.close
        exit_status = ...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            102
            views
        
    Simulating command prompt commands
                "Answering a cli prompt in ruby with open3?" is a possible duplicate question but it has no answer.
I need to write a program which compiles and executes a C program, gives inputs and returns the ...
            
        
       
    
            0
            votes
        
        
            1
            answer
        
        
            68
            views
        
    How to execute subprocesses in Ruby as fast as possible?
                We have a Rails application, which interfaces with iOS and web clients. Currently we are spawning subprocesses from a Rails controller using Open3 to retrieve and send data to a chat server, which ...
            
        
       
     
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
        