0

Is there a way in PHP to make exec() or one of its variants run a system command that needs user input in the execution session. Can be an FTP transfer for example or even just a print statement command with more flag. Say for e.g. in Windows command prompt I do a type bigfile.txt | more It gives me one screen of output and then I use the keyboard to have the next line come up.

Is there a way to capture this behavior using any of the PHP command line execution functions, when running from the browser? If not in standard PHP are there any PEAR/PECL resources which anyone has used before which does this?

Undefined Variable
  • 4,196
  • 10
  • 40
  • 69

1 Answers1

0

You can probably do this with proc_open, which can be used in a non-blocking manner, and gives you input and output pipes.

However, as a rule of thumb, I'd only attempt this as a last resort. Using a non-interactive executable, or a native PHP library will usually be far more maintainable. For example, I'm struggling to come up with a reason you'd ever want to proc_open('mycommand | more') when you can just exec('mycommand')

Frank Farmer
  • 38,246
  • 12
  • 71
  • 89