phpconsoleexecshell-execpassthru

PHP executing commands on software console


I have executed the twinkle-console by using shell_exec and it works perfectly

unknown@mrunknown-HP-650:~$ twinkle-console

Twinkle 1.10.1, October 7, 2016 Copyright (C) 2005-2015 Michel de Boer and contributors

Users: * profile profile1

Local IP: 255.255.255.255

profile: registering phone...

Twinkle>

now im looking to write & execute command in last line by using this code

    <?php
$resault = shell_exec("twinkle-console");
echo $resault."\n";
$resault = system("quit");
echo "OK \n";

but it reponse :

quit:not found

Thank you


Solution

  • shell_exec doesn't support sending input to the running program, and in any case, system is the wrong way to do that (it starts a new program with whatever you give it). Instead, use proc_open to run the program and get a pipe to its input, and write your commands to that.