Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Exec functions with php

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Exec functions with php

Postby nishaun » Thu Dec 06, 2012 3:18 pm

Hello I am on a dedicated Apache server... I have been trying to run a test file exec works but I can't get any output. The function neither creates a file nor returns output... (I also tried an int main)
Here is the code

Code: Select all
<?
echo "lalla";
echo exec("testfile.exe");
echo "lalla";
?>
<?
print exec("uptime");
echo "\n<br/>";
     passthru("who");
     
echo "<br/>";
//passthru("fortune");     
?>
<?
$output = shell_exec('testfile.exe');
echo "<pre>$output</pre>x";
?>
<?
print  shell_exec("uptime")or die('error');
print  shell_exec("testfile.exe")or die('error');
?>


This returns...

lallalalla 00:09:29 up 2 days, 15:08, 1 user, load average: 0.00, 0.00, 0.00
XXXXXX Jun 29 09:36 (modemcableXXXXXXX)
x 00:09:29 up 2 days, 15:08, 1 user, load average: 0.00, 0.00, 0.00

here is the code in testfile.exe (C++)

Code: Select all
#include <iostream>
#include <fstream>



using namespace std;




char main(int argc, char *argv[]){
   char sam[]="done";
   fstream finals;
   finals.open("rin3d.txt",ios::out | ios::app );

   if(argc==1){
   finals<<"isgood";
   
   }else{
   finals<<argv[1];
   
   }



   finals.close();
   return sam[0];

}
nishaun
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Dec 06, 2012 3:02 pm

Re: Exec functions with php

Postby egami » Fri Dec 14, 2012 8:53 am

Two things to remember.


1. If you're trying to run a shell argument from the webserver, the shell is being run as "apache" or "nobody" depending on your distro..

Thus, you'll need to make sure that this user has sudo privis in order to run the commands in question.


2. When you run the PHP script in your shell, it's running as you, and will have completely different permissions.


You can see all of this by doing tail -f /var/log/http/errors.log
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to PHP coding => General

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.