Ruby allows you to execute commands • Nix terminal through System , Exec , Irb , etc., but I can’t save a session between commands. That is, I open the console application in it through, for example, exec("./app") , but I cannot execute internal commands, as I would have done through a normal session /bin/sh .

 # ./app app> do_something 

Here this do_something and "falls off".

Thanks who will respond, maybe the library knows about this topic, I’m glad about everything.

UPD: That is, I have ./app and inside it I need to perform a series of actions by catching the output of information and send commands further on its basis. And the problem that I encounter is when the program reaches the application launch command, it redirects me to the terminal and is interrupted (waiting for the current program to finish), and I need to execute more commands inside the opened ./app .

  • Speech about preserving the history of executed commands - aleksandr barakin
  • Specify what kind of "session" it is, yes. - D-side
  • @ D-side Yes, I beg your pardon. Corrected - gJamDev
  • @alexanderbarakin corrected the question - gJamDev

1 answer 1

Read the documentation carefully.

exec does "a little bit" not what you expect .

External command

... it replaces the current Ruby process. That is, on this line your program ends , instead of it, the OS sticks the process that you started.

Most likely, you need the Open3 module from the standard library, specifically the popen3 and / or popen2 . They start a new process, hooking Ruby-controlled threads to its standard IO threads, and also create a separate Thread that waits for the process to complete.

What you would enter from the keyboard, submit to the received stdin new process, and do not forget to read its stdout and stderr , since the size of their buffers is usually limited, and their content can hang the program. The documentation has details about it.

  • Thank you very much @ D-side! I will try - gJamDev