Reputation: 2946
I have a shell script that requires input during runtime. Is it possible to echo input into the shell script during the exec()?
IE in a normal shell: $ ./script.sh
Input: Whats your favorite color: [Type your answer] Red
Output: Your favorite color is Red.
Upvotes: 1
Views: 3392
Reputation: 5431
I'm not sure exactly which side you are asking for, but I will answer both anyway.
From PHP, you can read user input from the shell. It can be done using the readline() function or simply using streams. Depending on the PHP version you are using and the environment, it can be either php://input or php://stdin. You can simply fopen() on those and read as usual.
If you want to interact with a shell script you are calling, you will need to use proc_open() rather than exec. It is a little more trouble, but there are no ways around. The function will provide you with separate streams for input, output and error, you can read them as needed to do your task.
Upvotes: 3