简体   繁体   中英

Ruby open interactive sub process within the shell

I want to use ruby and in one moment open another program (cfdisk) and let the user interact with it, then return to my code

I can use exec "cfdisk; ruby another.rb"

but that is very hacky and certainly not the right thing to do

I know about Open3 but i dont know how to use it properly for my usecase. I know that when I use capture3 on irb on Windows it says:

["Running under a virtual console, enabling 256/true-color support\\n", "Screen size 28640x499 is not supported; limit 500x500.\\nCheck the TERM environment variable.\\n", #]

In Arch it opens it but the graphical output isnt present, the keystrokes are registered, they work (for example mc exits with F10) but the window isnt there, just blinking cursor.

parted exits immediately

Tried popen3 but I had no luck with it either

What is wrong with system for this case?

  • The exec ruby command replaces the running process, so it will not return to your code.
  • The Open3 library is used when you want to capture stdout and stderr.

Isn't this what you are looking for?

puts "here"
system "cfdisk"
puts 'there'

If you have some screen related issues, this is another issue that you might be able to resolve with different TERM value in the environment variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM