I have a php script that I use to execute bash commands.
That bash command does not take argument at start, i.e.
ssh root@ip
However, when this command is executed, later it requires input from user.
So how can I accomplish this with php?
You can use popen which returns a file handle:
$handle = popen("ssh root@ip", "w");
fwrite($handle, "This is send as stdin\n");
// ...
pclose($handle);
Example:
<?php
$handle = popen("cat - > a.txt", "w");
fwrite($handle, "hello world\n");
// ...
pclose($handle);
?>
Will create a.txt with contains hello world.
popen stands for process open, and returns the process's standard input to $handle.fwrite three times or write a multiline string: fwrite($handle, "a\nb\nc\n")