0

I have multistep command, that asks for several questions in the process. I need to execute it from within the code.

php command.php
> What is your name?
User Smith
> What is your age?
25
> You are old enough!

But when I call it with exec it is just stuck.

What I expect, is something like:

<?php

$result = exec('php command.php')->next('User Smith')->next('25');

if ($result->response === 'You are old enough!') echo "Yahoo";
else  echo "Oh no!";
AidOnline01
  • 712
  • 7
  • 19

1 Answers1

1

We can chain commands using the pipe operator. We can do it like that:

exec('(echo 'User Smith' & echo '25') | php command.php')

The direction is from right to left.

Pipe multiple commands into a single command

AidOnline01
  • 712
  • 7
  • 19