akkad Posted July 31, 2007 Share Posted July 31, 2007 Hi, my probelm is that i have full access to the shell of the server (fedora 3.1) but running this code in a php file on xampp server that i have on the same server , i am not getting the output even when i am trying to pipe the output to an html file . <code> shell_exec("cat `find ./logs -name access.log*` | grep akadi_icho | ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html>akadi_icho.html"); </code> but when i am running this code on the shell directly : <code> cat `find ./logs -name access.log*` | grep akadi_icho| ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html>akadi_icho.html </code> it is working perfectly. so i have tried to run the code in parts : <code> shell_exec("cat `find ./logs -name access.log*` | grep akadi_icho"); </code> this part is working, but when i am running the whole part i am not getting any output. so plz can u help me to figure out the problem. Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/ Share on other sites More sharing options...
Vizor Posted July 31, 2007 Share Posted July 31, 2007 Shell_exec() returns it's output so can be assigned to a variable, try echoing that. Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-311734 Share on other sites More sharing options...
akkad Posted July 31, 2007 Author Share Posted July 31, 2007 thnx for ur reply but i have tried that also but its not outputting anything. Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-311746 Share on other sites More sharing options...
effigy Posted July 31, 2007 Share Posted July 31, 2007 Combine STDERR with STDOUT (2>&1) to see if any errors show. Also, try using system so you can get the actual return value from the command. Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-311817 Share on other sites More sharing options...
akkad Posted August 1, 2007 Author Share Posted August 1, 2007 Hi again , i appreciate ur help, i have used system() function in two ways: $last_line = system( shell_exec('cat `find ./logs -name access.log*`|grep $userid |./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html'), $retval); echo $retval; the output was: Warning: system() [function.system]: Cannot execute a blank command in /opt/lampp/htdocs/xampp/thesis/traffic.php on line 28 where line 28 is the system command by it self. the second way : $last_line = system('cat `find ./logs -name access.log*`|grep $userid |./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html', $retval); echo $retval; the output was : 126 related to the combining STDERR with STDOUT i dont know the right syntax if u can give me an example that i can figure out how to use it Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-312678 Share on other sites More sharing options...
effigy Posted August 1, 2007 Share Posted August 1, 2007 i have used system() function in two ways: The first is incorrect, the second is correct. Since you're using single quotes $userid will not be interpolated. If double quotes don't fix the problem, try running pwd to make sure you're in the right directory. related to the combining STDERR with STDOUT i dont know the right syntax if u can give me an example that i can figure out how to use it <pre> <?php ### This won't show you anything because it only returns STDOUT. echo shell_exec('notacmd'); echo '<hr>'; ### This will show the error because it returns STDOUT and STDERR. echo shell_exec('notacmd 2>&1'); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-312810 Share on other sites More sharing options...
hvle Posted August 1, 2007 Share Posted August 1, 2007 thanks very much effigy can you please explain this '2>&1'? because this does the trick for my code. Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-313411 Share on other sites More sharing options...
effigy Posted August 2, 2007 Share Posted August 2, 2007 "1" is the file descriptor for STDOUT. "2" is the file descriptor for STDERR. Therefore, 2>&1 is sending STDERR to STDOUT. Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-313585 Share on other sites More sharing options...
akkad Posted August 2, 2007 Author Share Posted August 2, 2007 finally i could find the solution which is : in php code i couldn't run a perl script without calling the perl or bash to run it , so i have done that in the following way: <code> echo shell_exec("cat /opt/lampp/htdocs/xampp/thesis/logs/access.log.* | grep $userid | /usr/bin/perl ./calamaris/calamaris -a -P 60 -T 0 -r 400 -d 500 -u -O -F html"); </code> thanx buddy Quote Link to comment https://forums.phpfreaks.com/topic/62631-solved-shell_exec-problems/#findComment-313856 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.