The first answer is correct. You probably want to use popen()
or some other function that will return a channel that you can write in the same way as a file opened with fopen()
or file()
.
<?php $pipe = popen("sudo -u dummy passwd testUser testUserPassword", 'r'); fwrite($pipe, "dummyPasswd\r\n"); pclose($pipe); echo "done"; ?>
I have not tested this, but it is a general idea of ββwhat you seem to be going to do. You will notice that this setting does not provide output from executed commands. To do this, you need to use proc_open()
, which is a bit more difficult to work with, but provides bi-directional support.
source share