By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,740 Members | 1,820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,740 IT Pros & Developers. It's quick & easy.

exec()

P: n/a
can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.

Please help me,
Peter
Jul 17 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
Piotr Wolski wrote:
can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.

Please help me,
Peter


what do you think ls, who, and others are written in?? What are you trying do
do? does the webserver user have access to said "c" program? do you have the
correct privs set on the files? What OS? does the program take parameters, if
so, show us the code of how you are executing them. Have you read the docs
carefully and seen the examples given there??
--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #2

P: n/a
On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wo****@cs.purdue.edu> wrote:
can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.


Neither do I. Post some details. 'ls' and 'who' are both C programs, not that
it actually matters what they're originally written in.

Odds are it's a permissions problem of some sort.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3

P: n/a
Michael Austin wrote:
Piotr Wolski wrote:
can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't
know why.

Please help me,
Peter

what do you think ls, who, and others are written in?? What are you
trying do do? does the webserver user have access to said "c" program?
do you have the correct privs set on the files? What OS? does the
program take parameters, if so, show us the code of how you are
executing them. Have you read the docs carefully and seen the examples
given there??


ok ls and others are written in C however they are included as system
programms(commands). My C programms compiled ,executes perfectly from
command line, however they cannot be executed from the web. unix system.
it doesn't matter if the programms takes or doesn't take parameters. I'm
trying the simplest C programm that should write out few letters. i even
added compiled programm to the PATH directory. and the result is the same..

i'm trying to do so:
exec("progs");
or passthru("progs");
even when i add all the path it doesn't take any result.
i tried exec("./progs 2> error_file");
when compiled programm is in the directory where the script is, then the
error_file looks like:
../progs: syntax error at line 1: '(' unexpected
what the hell does it mean??
../progs exectuted from command line does what he should do very good..

please for help
Jul 17 '05 #4

P: n/a
Andy Hassall wrote:
On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wo****@cs.purdue.edu> wrote:

can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.

Neither do I. Post some details. 'ls' and 'who' are both C programs, not that
it actually matters what they're originally written in.

Odds are it's a permissions problem of some sort.


i changed permissions to my compiled C programms: +rwx and nothing changed:(
Jul 17 '05 #5

P: n/a
Piotr Wolski wrote:

can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.

What do you mean, "can not execute"? Do you receive a PHP error message?
A system error message? No error, just doesn't see to run?

Details details details.

Brian Rodenborn
Jul 17 '05 #6

P: n/a
Piotr Wolski wrote:
i'm trying to do so:
exec("progs");
or passthru("progs");
even when i add all the path it doesn't take any result.
i tried exec("./progs 2> error_file");
when compiled programm is in the directory where the script is, then the
error_file looks like:
./progs: syntax error at line 1: '(' unexpected
what the hell does it mean??
./progs exectuted from command line does what he should do very good..
does the webserver know where .progs lives? you would need to include the full
filespec if it is not where the webserver thinks it is or add the path to the
httpd.conf (apache - you'll have to figure it out for yourself on IIS). To find
out where the webserver thinks it should be looking, use something like this:

$out = exec("pwd");
echo $out ."<br>\n";
or
$output = `pwd`;
echo $output ."<br>\n";

Now, does progs live in this directory? if not, how do you expect the server to
find it???

please for help


--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #7

P: n/a
Michael Austin wrote:
Piotr Wolski wrote:
i'm trying to do so:
exec("progs");
or passthru("progs");
even when i add all the path it doesn't take any result.
i tried exec("./progs 2> error_file");
when compiled programm is in the directory where the script is, then
the error_file looks like:
./progs: syntax error at line 1: '(' unexpected
what the hell does it mean??
./progs exectuted from command line does what he should do very good..

does the webserver know where .progs lives? you would need to include
the full filespec if it is not where the webserver thinks it is or add
the path to the httpd.conf (apache - you'll have to figure it out for
yourself on IIS). To find out where the webserver thinks it should be
looking, use something like this:

$out = exec("pwd");
echo $out ."<br>\n";
or
$output = `pwd`;
echo $output ."<br>\n";

Now, does progs live in this directory? if not, how do you expect the
server to find it???


The programm lives exactly in the directory that your short script shows
on.
Jul 17 '05 #8

P: n/a
Piotr Wolski wrote:
Michael Austin wrote:
Piotr Wolski wrote:
i'm trying to do so:
exec("progs");
or passthru("progs");
even when i add all the path it doesn't take any result.
i tried exec("./progs 2> error_file");
when compiled programm is in the directory where the script is, then
the error_file looks like:
./progs: syntax error at line 1: '(' unexpected
what the hell does it mean??
./progs exectuted from command line does what he should do very good..


does the webserver know where .progs lives? you would need to include
the full filespec if it is not where the webserver thinks it is or add
the path to the httpd.conf (apache - you'll have to figure it out for
yourself on IIS). To find out where the webserver thinks it should be
looking, use something like this:

$out = exec("pwd");
echo $out ."<br>\n";
or
$output = `pwd`;
echo $output ."<br>\n";

Now, does progs live in this directory? if not, how do you expect the
server to find it???


The programm lives exactly in the directory that your short script shows
on.


why it returns so strange error?:
../progs: syntax error at line 1: '(' unexpected

?????progs is compiled program..who can explain that?
Jul 17 '05 #9

P: n/a
Piotr Wolski wrote:
Piotr Wolski wrote:
Michael Austin wrote:
Piotr Wolski wrote:

i'm trying to do so:
exec("progs");
or passthru("progs");
even when i add all the path it doesn't take any result.
i tried exec("./progs 2> error_file");
when compiled programm is in the directory where the script is, then
the error_file looks like:
./progs: syntax error at line 1: '(' unexpected
what the hell does it mean??
./progs exectuted from command line does what he should do very good..


does the webserver know where .progs lives? you would need to
include the full filespec if it is not where the webserver thinks it
is or add the path to the httpd.conf (apache - you'll have to figure
it out for yourself on IIS). To find out where the webserver thinks
it should be looking, use something like this:

$out = exec("pwd");
echo $out ."<br>\n";
or
$output = `pwd`;
echo $output ."<br>\n";

Now, does progs live in this directory? if not, how do you expect the
server to find it???


The programm lives exactly in the directory that your short script
shows on.

why it returns so strange error?:
./progs: syntax error at line 1: '(' unexpected

?????progs is compiled program..who can explain that?


Here is a "wierd" example from the docs:

<?php
exec('/bin/sh -c "/bin/tar -xzf /tmp/'.$filename.' install/desc-file
install/info-file install/deps-file"');
?>

so yours would look like:

exec('/bin/sh -c "/full/file/dir/progs 2 >error_log"');

have you tried using back-tick "`" method?
is the webserver owner also the owner or in the same group as the progs file?

what is line 1 of the progs program?

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #10

P: n/a
Michael Austin wrote:
Piotr Wolski wrote:
Piotr Wolski wrote:
Michael Austin wrote:

Piotr Wolski wrote:

> i'm trying to do so:
> exec("progs");
> or passthru("progs");
> even when i add all the path it doesn't take any result.
> i tried exec("./progs 2> error_file");
> when compiled programm is in the directory where the script is,
> then the error_file looks like:
> ./progs: syntax error at line 1: '(' unexpected
> what the hell does it mean??
> ./progs exectuted from command line does what he should do very good..

does the webserver know where .progs lives? you would need to
include the full filespec if it is not where the webserver thinks it
is or add the path to the httpd.conf (apache - you'll have to figure
it out for yourself on IIS). To find out where the webserver thinks
it should be looking, use something like this:

$out = exec("pwd");
echo $out ."<br>\n";
or
$output = `pwd`;
echo $output ."<br>\n";

Now, does progs live in this directory? if not, how do you expect
the server to find it???
The programm lives exactly in the directory that your short script
shows on.
why it returns so strange error?:
./progs: syntax error at line 1: '(' unexpected

?????progs is compiled program..who can explain that?

Here is a "wierd" example from the docs:

<?php
exec('/bin/sh -c "/bin/tar -xzf /tmp/'.$filename.' install/desc-file
install/info-file install/deps-file"');
?>

so yours would look like:

exec('/bin/sh -c "/full/file/dir/progs 2 >error_log"');


I tried this and in error_log file is the same as before that there's
syntax error at line 1: '(' unexpected..

have you tried using back-tick "`" method? no i haven't..
could you let me know what the code should look like?
is the webserver owner also the owner or in the same group as the progs
file? http://www.cs.purdue.edu/help/www/using-cgi.html <--here is everything
about configuration of the server i'm using..

what is line 1 of the progs program?


i don't know cause it's already compiled program..
Jul 17 '05 #11

P: n/a
Piotr Wolski wrote:
Michael Austin wrote:
Piotr Wolski wrote:
Piotr Wolski wrote:

Michael Austin wrote:

> Piotr Wolski wrote:
>
>> i'm trying to do so:
>> exec("progs");
>> or passthru("progs");
>> even when i add all the path it doesn't take any result.
>> i tried exec("./progs 2> error_file");
>> when compiled programm is in the directory where the script is,
>> then the error_file looks like:
>> ./progs: syntax error at line 1: '(' unexpected
>> what the hell does it mean??
>> ./progs exectuted from command line does what he should do very
>> good..
>
>
>
>
>
>
> does the webserver know where .progs lives? you would need to
> include the full filespec if it is not where the webserver thinks
> it is or add the path to the httpd.conf (apache - you'll have to
> figure it out for yourself on IIS). To find out where the webserver
> thinks it should be looking, use something like this:
>
> $out = exec("pwd");
> echo $out ."<br>\n";
> or
> $output = `pwd`;
> echo $output ."<br>\n";
>
> Now, does progs live in this directory? if not, how do you expect
> the server to find it???
>

The programm lives exactly in the directory that your short script
shows on.


why it returns so strange error?:
./progs: syntax error at line 1: '(' unexpected

?????progs is compiled program..who can explain that?


Here is a "wierd" example from the docs:

<?php
exec('/bin/sh -c "/bin/tar -xzf /tmp/'.$filename.' install/desc-file
install/info-file install/deps-file"');
?>

so yours would look like:

exec('/bin/sh -c "/full/file/dir/progs 2 >error_log"');

I tried this and in error_log file is the same as before that there's
syntax error at line 1: '(' unexpected..

have you tried using back-tick "`" method?


no i haven't..
could you let me know what the code should look like?
is the webserver owner also the owner or in the same group as the
progs file?


http://www.cs.purdue.edu/help/www/using-cgi.html <--here is everything
about configuration of the server i'm using..

what is line 1 of the progs program?


i don't know cause it's already compiled program..


Well if this error is in the error_file then the output is from the program
itself, not the web server. You will need to find out who wrote the code and
broke it.

can you execute the "c" program from a command prompt (log into the box and
execute it?) if not, there is not much else we can do for you here...

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #12

P: n/a
Michael Austin wrote:
Piotr Wolski wrote:
Michael Austin wrote:
Piotr Wolski wrote:

Piotr Wolski wrote:

> Michael Austin wrote:
>
>> Piotr Wolski wrote:
>>
>>> i'm trying to do so:
>>> exec("progs");
>>> or passthru("progs");
>>> even when i add all the path it doesn't take any result.
>>> i tried exec("./progs 2> error_file");
>>> when compiled programm is in the directory where the script is,
>>> then the error_file looks like:
>>> ./progs: syntax error at line 1: '(' unexpected
>>> what the hell does it mean??
>>> ./progs exectuted from command line does what he should do very
>>> good..
>>
>>
>>
>>
>>
>>
>>
>> does the webserver know where .progs lives? you would need to
>> include the full filespec if it is not where the webserver thinks
>> it is or add the path to the httpd.conf (apache - you'll have to
>> figure it out for yourself on IIS). To find out where the
>> webserver thinks it should be looking, use something like this:
>>
>> $out = exec("pwd");
>> echo $out ."<br>\n";
>> or
>> $output = `pwd`;
>> echo $output ."<br>\n";
>>
>> Now, does progs live in this directory? if not, how do you expect
>> the server to find it???
>>
>
> The programm lives exactly in the directory that your short script
> shows on.

why it returns so strange error?:
./progs: syntax error at line 1: '(' unexpected

?????progs is compiled program..who can explain that?


Here is a "wierd" example from the docs:

<?php
exec('/bin/sh -c "/bin/tar -xzf /tmp/'.$filename.'
install/desc-file install/info-file install/deps-file"');
?>

so yours would look like:

exec('/bin/sh -c "/full/file/dir/progs 2 >error_log"');


I tried this and in error_log file is the same as before that there's
syntax error at line 1: '(' unexpected..

have you tried using back-tick "`" method?

no i haven't..
could you let me know what the code should look like?
is the webserver owner also the owner or in the same group as the
progs file?

http://www.cs.purdue.edu/help/www/using-cgi.html <--here is
everything about configuration of the server i'm using..

what is line 1 of the progs program?


i don't know cause it's already compiled program..

Well if this error is in the error_file then the output is from the
program itself, not the web server. You will need to find out who wrote
the code and broke it.

can you execute the "c" program from a command prompt (log into the box
and execute it?) if not, there is not much else we can do for you here...


Yes sure, i can execute this program from command line,i can even
write this programm here cause it's very simple program written just for
tests:

#include <stdlib.h>

int main()
{
printf("test");
return 0;
}

And that's all program..
So what can you say about that? this problem is really strange..i hope
you'll find some clue for that cause i'm working under it 24h/day and
still nothing..
thanks, peter
Jul 17 '05 #13

P: n/a
On Mon, 12 Jul 2004 14:22:28 -0500, Piotr Wolski
<wo****@cs.purdue.edu> wrote:
Andy Hassall wrote:
On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wo****@cs.purdue.edu> wrote:

can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.

Neither do I. Post some details. 'ls' and 'who' are both C programs, not that
it actually matters what they're originally written in.

Odds are it's a permissions problem of some sort.


i changed permissions to my compiled C programms: +rwx and nothing changed:(


it certainly sounds like a permission problem ...

does the webserver have permission to use the directory in which the
binary executable lives? (even though the file itself might have
correct permission, if the webserver user can't access the directory,
it won't be able to run the file).
Jul 17 '05 #14

P: n/a
Herbie Cumberland wrote:
On Mon, 12 Jul 2004 14:22:28 -0500, Piotr Wolski
<wo****@cs.purdue.edu> wrote:

Andy Hassall wrote:
On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wo****@cs.purdue.edu> wrote:

can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.
Neither do I. Post some details. 'ls' and 'who' are both C programs, not that
it actually matters what they're originally written in.

Odds are it's a permissions problem of some sort.


i changed permissions to my compiled C programms: +rwx and nothing changed:(

it certainly sounds like a permission problem ...

does the webserver have permission to use the directory in which the
binary executable lives? (even though the file itself might have
correct permission, if the webserver user can't access the directory,
it won't be able to run the file).


the programm is example in directory 'example' so the path is
'example/program', example and the programm have the same full permissions..
Jul 17 '05 #15

P: n/a
Piotr Wolski wrote:
Michael Austin wrote:
Piotr Wolski wrote:
Michael Austin wrote:

Piotr Wolski wrote:

> Piotr Wolski wrote:
>
>> Michael Austin wrote:
>>
>>> Piotr Wolski wrote:
>>>
>>>> i'm trying to do so:
>>>> exec("progs");
>>>> or passthru("progs");
>>>> even when i add all the path it doesn't take any result.
>>>> i tried exec("./progs 2> error_file");
>>>> when compiled programm is in the directory where the script is,
>>>> then the error_file looks like:
>>>> ./progs: syntax error at line 1: '(' unexpected
>>>> what the hell does it mean??
>>>> ./progs exectuted from command line does what he should do very
>>>> good..
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> does the webserver know where .progs lives? you would need to
>>> include the full filespec if it is not where the webserver thinks
>>> it is or add the path to the httpd.conf (apache - you'll have to
>>> figure it out for yourself on IIS). To find out where the
>>> webserver thinks it should be looking, use something like this:
>>>
>>> $out = exec("pwd");
>>> echo $out ."<br>\n";
>>> or
>>> $output = `pwd`;
>>> echo $output ."<br>\n";
>>>
>>> Now, does progs live in this directory? if not, how do you expect
>>> the server to find it???
>>>
>>
>> The programm lives exactly in the directory that your short script
>> shows on.
>
>
>
>
>
>
> why it returns so strange error?:
>
>
> ./progs: syntax error at line 1: '(' unexpected
>
> ?????progs is compiled program..who can explain that?

Here is a "wierd" example from the docs:

<?php
exec('/bin/sh -c "/bin/tar -xzf /tmp/'.$filename.'
install/desc-file install/info-file install/deps-file"');
?>

so yours would look like:

exec('/bin/sh -c "/full/file/dir/progs 2 >error_log"');


I tried this and in error_log file is the same as before that there's
syntax error at line 1: '(' unexpected..
have you tried using back-tick "`" method?

no i haven't..
could you let me know what the code should look like?

is the webserver owner also the owner or in the same group as the
progs file?

http://www.cs.purdue.edu/help/www/using-cgi.html <--here is
everything about configuration of the server i'm using..
what is line 1 of the progs program?
i don't know cause it's already compiled program..


Well if this error is in the error_file then the output is from the
program itself, not the web server. You will need to find out who
wrote the code and broke it.

can you execute the "c" program from a command prompt (log into the
box and execute it?) if not, there is not much else we can do for you
here...

Yes sure, i can execute this program from command line,i can even write
this programm here cause it's very simple program written just for tests:

#include <stdlib.h>

int main()
{
printf("test");
return 0;
}

And that's all program..
So what can you say about that? this problem is really strange..i hope
you'll find some clue for that cause i'm working under it 24h/day and
still nothing..
thanks, peter


I don't do this often, but, if you would like, send me a private email with:

ls -la progs and the directories down to progs, uid/gid of the webserver owner,
should have at least group:read access for the webserver owner.

example:

d?????? uid/gid abc
d?????? uid/gid xxxx
d?????? uid/gid yyy
-rwe?????? uid/gid progs

if you do this, you will probably find your problem also try setting the file
to permissions 777 and all of the directories (temporarily as a test) to see if
there is any difference.

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #16

P: n/a
Michael Austin wrote:

<snippage>

I don't do this often, but, if you would like, send me a private email
with:

ls -la progs and the directories down to progs, uid/gid of the
webserver owner,
should have at least group:read access for the webserver owner.

example:

d?????? uid/gid abc
d?????? uid/gid xxxx
d?????? uid/gid yyy
-rwe?????? uid/gid progs

if you do this, you will probably find your problem also try setting
the file to permissions 777 and all of the directories (temporarily as a
test) to see if there is any difference.


try something like:

exec('./progs',$a1,$a2);
print_r($a1);
echo "A2 = $a2\n";

helps if we read the docs:

exec ( string command [, array output [, int return_var]])

exec() executes the given command, however it ***does not output anything***. It
simply returns the last line from the result of the command. If you need to
execute a command and have all the data from the command passed directly back
without any interference, use the passthru() function.

then parse through the output array to get the results.

if you want this in the php script then using
$out = `./test`; \\ back-ticks (key next to the !/1 key "~/`")
echo $out;

or the system() command

echo system('./test');

--
Michael Austin.
Consultant - Available.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Jul 17 '05 #17

P: n/a
Piotr Wolski wrote:
can anyone help me:

using exec() function in PHP i can execute linux programms like ls,who
and other, however i can not execute C programms and i really don't know
why.

Please help me,
Peter


i've solved my problem:

webserver is on SPARC machine;) and I compiled ewerything on the intel
x86 machine. thats why my C programms didin't want to execute.When i
compiled them one more time on SPARC everything is ok.

thanks everyone for teying to solve my problem.
Jul 17 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.