Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute an interactive command from PHP?

Tags:

linux

shell

php

I need to execute kdiff3 command in my desktop machine (localhost) from PHP script (using browser, not command line). I've given permission for the user www-data that is executing the scripts to execute kdiff3 using visudo. In fact, if I log in as www-data I can execute it without problems (sudo kdiff3 ..., it's configured to not ask for a password at all).

The problem is when I try to execute this command from a PHP script. I've tried this:

$output = shell_exec("sudo kdiff3 -m $file.def.old $file $file.def -o $file");

and nothing happens (output is NULL). If I try a non interactive command, like ls it works:

$output = shell_exec("ls");

What's happening? Why cannot execute an interactive command?

like image 291
Ivan Avatar asked Dec 03 '22 05:12

Ivan


1 Answers

Try passthru($cmd);

It will allow user's I/O on the Terminal screen.

like image 145
Francisco Luz Avatar answered Dec 24 '22 17:12

Francisco Luz