ashok!!! Posted June 1, 2012 Share Posted June 1, 2012 guys....... need help!! there is command which when executed in terminal gives the output without error in 5 seconds. but when i run the same in a php file using shell_exec($cmd) i m getting error. please help me out here. thanq in advance Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/ Share on other sites More sharing options...
PravinS Posted June 1, 2012 Share Posted June 1, 2012 what error you are getting, generally shell_exec() command is disabled on servers. Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/#findComment-1350230 Share on other sites More sharing options...
ashok!!! Posted June 1, 2012 Author Share Posted June 1, 2012 when i tried shell_exec(ls) its working fine... i mean.. i m getting all the files/folders in the directory in which the php file is present. actually... i can send sms from the terminal through my mobile (connected to the computer) which takes about 5 secs. but when i tried running the same in the php file..... i m getting error as "device not found". i also saw some posts telling that the commands which take time to execute are giving errors when ran in a php file. Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/#findComment-1350233 Share on other sites More sharing options...
PravinS Posted June 1, 2012 Share Posted June 1, 2012 Try "popen" function http://php.net/manual/en/function.popen.php Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/#findComment-1350266 Share on other sites More sharing options...
trq Posted June 1, 2012 Share Posted June 1, 2012 Post your code. Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/#findComment-1350271 Share on other sites More sharing options...
ashok!!! Posted June 1, 2012 Author Share Posted June 1, 2012 this is my php file <?php $msg=$_GET['messagee']; $num=$_GET['senderr']; $output = popen("echo $msg | /usr/bin/gammu --sendsms TEXT $num &", 'r'); echo "'$output'; " . gettype($output) . "\n"; ?> this was my output: 'Resource id #2'; resource Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/#findComment-1350279 Share on other sites More sharing options...
ManiacDan Posted June 1, 2012 Share Posted June 1, 2012 1) he meant "try to read the manual and learn how to use the popen function" 2) Never ever ever, under any circumstances, EVER run user input through the shell without using escapeshellcmd Link to comment https://forums.phpfreaks.com/topic/263469-shell-commands-in-php/#findComment-1350308 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.