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!";

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.