popen3

Kill a process called using open3 in ruby

◇◆丶佛笑我妖孽 提交于 2021-01-27 04:46:29
问题 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 continuously (I can't handle or modify the code of "app" in order to avoid this). In a ruby script there's a line like this: text = "long text that will be used by app" output = system("ROUTE_TO_FOLDER/app < #{text}") Now, if text is well written,

How to fix hanging popen3 in Ruby?

别来无恙 提交于 2019-12-29 05:19:45
问题 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 is never reached. I suspect, I am suffering from buffering, but how do I fix this? #!/usr/bin/env ruby require 'open3' Open3.popen3("cat") do |stdin, stdout, stderr, wait_thr| stdin.puts "foobar" puts "stdin done" stdout.each_line { |line| puts

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

℡╲_俬逩灬. 提交于 2019-12-23 21:19:55
问题 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 executable wasn't found (and raise a special error for that). I know that the UNIX shell gives exit code 127 when command wasn't found. And when I execute $ foo in bash, I get -bash: foo: command not found , which is exactly the error message I want to

Ruby—Open3.popen3 / how to print the output

本小妞迷上赌 提交于 2019-12-21 12:34:11
问题 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 so far: mysqlimp = "mysql -u #{mysqllocal['user']} " mysqlimp << "-h #{mysqllocal['host']} " mysqlimp << "-p#{mysqllocal['pass']} " mysqlimp << "#{mysqllocal['db']}" Open3.popen3(mysqlimp) do |stdin, stdout, stderr, wthr| stdin.write "DROP DATABASE IF EXISTS #{mysqllocal['db']};\n" stdin.write "CREATE DATABASE #

Python equivalent to find -exec

你说的曾经没有我的故事 提交于 2019-12-11 04:09:53
问题 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 python equivalent of this be? My naive aproach would be: for (root,files,subdirs) in os.walk('/tmp/mount'): for file in files: if '.rpmsave' in file: os.remove(file) surely there is a better, more pythonic way of doing this? 回答1: You've actually got two questions here — first, why your Popen construction

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

扶醉桌前 提交于 2019-12-01 16:47:53
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 this: Open3.popen3("console_REPL_process") do |stdin, stdout, stderr, wait_thr| stdin.puts "a string of input" stdin.close_write stdout.each_line { |line| puts line } #successfully prints all the output end I want to do that many times in a row, without re-opening the process, as it takes a long time to start up. I know I have to close stdin in order for

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

时光怂恿深爱的人放手 提交于 2019-12-01 14:43:56
问题 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 this: Open3.popen3("console_REPL_process") do |stdin, stdout, stderr, wait_thr| stdin.puts "a string of input" stdin.close_write stdout.each_line { |line| puts line } #successfully prints all the output end I want to do that many times in a row, without re

How to fix hanging popen3 in Ruby?

China☆狼群 提交于 2019-11-29 01:33:22
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 is never reached. I suspect, I am suffering from buffering, but how do I fix this? #!/usr/bin/env ruby require 'open3' Open3.popen3("cat") do |stdin, stdout, stderr, wait_thr| stdin.puts "foobar" puts "stdin done" stdout.each_line { |line| puts line } puts "stdout done" puts wait_thr.value end puts "all done" stdout.each_line is waiting for further