1

What I'm looking for is to execute an interactive script and ask user for input. The input format may vary from times to times the program being called, so I need the original prompt from the callee script and redirect stdin to the callee.

Currently I find that the passthru() function in PHP just meets my need. However, is there an alternative to or ways to implement the passthru() function?

UPDATE

An example (simpler as the real situation) to explain myself:

puts `sudo apt-get -y upgrade`

The sudo command may ask user for password. For sudo, the input format remains constant, I could use popen for it. However what if the input format of the command being called is very complex and varies from times to times?

xiGUAwanOU
  • 325
  • 2
  • 16
  • you want to execute a linux command, and get the result back to ruby? – Vitali Mogilevsky Mar 24 '16 at 10:25
  • @VitaliMogilevsky Thx for your reply. Not exactly, I want to execute a command but don't need the output in Ruby. However I need to get the user input and pass them to the command being called. – xiGUAwanOU Mar 24 '16 at 10:30
  • Im not 100% sure what are you trying to do, you can read user input by setting param = gets, then use the param anywhere you want. if you want to use it in the command simply use it as regular string – Vitali Mogilevsky Mar 24 '16 at 10:35

1 Answers1

1

You may be able to achieve what you want with PTY.spawn. Have a look at this answer.

Community
  • 1
  • 1
rdupz
  • 2,204
  • 2
  • 13
  • 21