exec()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Piotr Wolski

    exec()

    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
  • Michael Austin

    #2
    Re: exec()

    Piotr Wolski wrote:
    [color=blue]
    > 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[/color]

    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
    :)

    Comment

    • Andy Hassall

      #3
      Re: exec()

      On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wolski@cs.purd ue.edu> wrote:
      [color=blue]
      >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.[/color]

      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 <andy@andyh.co. uk> / Space: disk usage analysis tool
      http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

      Comment

      • Piotr Wolski

        #4
        Re: exec()

        Michael Austin wrote:[color=blue]
        > Piotr Wolski wrote:
        >[color=green]
        >> 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[/color]
        >
        >
        > 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??
        >
        >[/color]

        ok ls and others are written in C however they are included as system
        programms(comma nds). 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

        Comment

        • Piotr Wolski

          #5
          Re: exec()

          Andy Hassall wrote:[color=blue]
          > On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wolski@cs.purd ue.edu> wrote:
          >
          >[color=green]
          >>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.[/color]
          >
          >
          > 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.[/color]

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

          Comment

          • Default User

            #6
            Re: exec()

            Piotr Wolski wrote:[color=blue]
            >
            > 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.[/color]


            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

            Comment

            • Michael Austin

              #7
              Re: exec()

              Piotr Wolski wrote:[color=blue]
              > 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..[/color]

              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???
              [color=blue]
              >
              > please for help[/color]

              --
              Michael Austin.
              Consultant - Available.
              Donations welcomed. Http://www.firstdbasource.com/donations.html
              :)

              Comment

              • Piotr Wolski

                #8
                Re: exec()

                Michael Austin wrote:[color=blue]
                > Piotr Wolski wrote:
                >[color=green]
                >> 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..[/color]
                >
                >
                > 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???
                >[/color]

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

                Comment

                • Piotr Wolski

                  #9
                  Re: exec()

                  Piotr Wolski wrote:[color=blue]
                  > Michael Austin wrote:
                  >[color=green]
                  >> Piotr Wolski wrote:
                  >>[color=darkred]
                  >>> 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..[/color]
                  >>
                  >>
                  >>
                  >> 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???
                  >>[/color]
                  >
                  > The programm lives exactly in the directory that your short script shows
                  > on.[/color]

                  why it returns so strange error?:


                  ../progs: syntax error at line 1: '(' unexpected

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

                  Comment

                  • Michael Austin

                    #10
                    Re: exec()

                    Piotr Wolski wrote:[color=blue]
                    > Piotr Wolski wrote:
                    >[color=green]
                    >> Michael Austin wrote:
                    >>[color=darkred]
                    >>> 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???
                    >>>[/color]
                    >>
                    >> The programm lives exactly in the directory that your short script
                    >> shows on.[/color]
                    >
                    >
                    > why it returns so strange error?:
                    >
                    >
                    > ./progs: syntax error at line 1: '(' unexpected
                    >
                    > ?????progs is compiled program..who can explain that?[/color]

                    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
                    :)

                    Comment

                    • Piotr Wolski

                      #11
                      Re: exec()

                      Michael Austin wrote:[color=blue]
                      > Piotr Wolski wrote:
                      >[color=green]
                      >> Piotr Wolski wrote:
                      >>[color=darkred]
                      >>> 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.[/color]
                      >>
                      >>
                      >>
                      >> why it returns so strange error?:
                      >>
                      >>
                      >> ./progs: syntax error at line 1: '(' unexpected
                      >>
                      >> ?????progs is compiled program..who can explain that?[/color]
                      >
                      >
                      > 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"') ;[/color]

                      I tried this and in error_log file is the same as before that there's
                      syntax error at line 1: '(' unexpected..
                      [color=blue]
                      >
                      > have you tried using back-tick "`" method?[/color]
                      no i haven't..
                      could you let me know what the code should look like?
                      [color=blue]
                      > is the webserver owner also the owner or in the same group as the progs
                      > file?[/color]
                      http://www.cs.purdue.edu/help/www/using-cgi.html <--here is everything
                      about configuration of the server i'm using..
                      [color=blue]
                      >
                      > what is line 1 of the progs program?
                      >[/color]

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

                      Comment

                      • Michael Austin

                        #12
                        Re: exec()

                        Piotr Wolski wrote:
                        [color=blue]
                        > Michael Austin wrote:
                        >[color=green]
                        >> Piotr Wolski wrote:
                        >>[color=darkred]
                        >>> 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?[/color]
                        >>
                        >>
                        >>
                        >> 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"') ;[/color]
                        >
                        >
                        > I tried this and in error_log file is the same as before that there's
                        > syntax error at line 1: '(' unexpected..
                        >[color=green]
                        >>
                        >> have you tried using back-tick "`" method?[/color]
                        >
                        > no i haven't..
                        > could you let me know what the code should look like?
                        >[color=green]
                        >> is the webserver owner also the owner or in the same group as the
                        >> progs file?[/color]
                        >
                        > http://www.cs.purdue.edu/help/www/using-cgi.html <--here is everything
                        > about configuration of the server i'm using..
                        >[color=green]
                        >>
                        >> what is line 1 of the progs program?
                        >>[/color]
                        >
                        > i don't know cause it's already compiled program..[/color]

                        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
                        :)

                        Comment

                        • Piotr Wolski

                          #13
                          Re: exec()

                          Michael Austin wrote:[color=blue]
                          > Piotr Wolski wrote:
                          >[color=green]
                          >> Michael Austin wrote:
                          >>[color=darkred]
                          >>> 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"') ;[/color]
                          >>
                          >>
                          >>
                          >> I tried this and in error_log file is the same as before that there's
                          >> syntax error at line 1: '(' unexpected..
                          >>[color=darkred]
                          >>>
                          >>> have you tried using back-tick "`" method?[/color]
                          >>
                          >>
                          >> no i haven't..
                          >> could you let me know what the code should look like?
                          >>[color=darkred]
                          >>> is the webserver owner also the owner or in the same group as the
                          >>> progs file?[/color]
                          >>
                          >>
                          >> http://www.cs.purdue.edu/help/www/using-cgi.html <--here is
                          >> everything about configuration of the server i'm using..
                          >>[color=darkred]
                          >>>
                          >>> what is line 1 of the progs program?
                          >>>[/color]
                          >>
                          >> i don't know cause it's already compiled program..[/color]
                          >
                          >
                          > 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...[/color]

                          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

                          Comment

                          • Herbie Cumberland

                            #14
                            Re: exec()

                            On Mon, 12 Jul 2004 14:22:28 -0500, Piotr Wolski
                            <wolski@cs.purd ue.edu> wrote:
                            [color=blue]
                            >Andy Hassall wrote:[color=green]
                            >> On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wolski@cs.purd ue.edu> wrote:
                            >>
                            >>[color=darkred]
                            >>>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.[/color]
                            >>
                            >>
                            >> 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.[/color]
                            >
                            >i changed permissions to my compiled C programms: +rwx and nothing changed:([/color]

                            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).


                            Comment

                            • Piotr Wolski

                              #15
                              Re: exec()

                              Herbie Cumberland wrote:[color=blue]
                              > On Mon, 12 Jul 2004 14:22:28 -0500, Piotr Wolski
                              > <wolski@cs.purd ue.edu> wrote:
                              >
                              >[color=green]
                              >>Andy Hassall wrote:
                              >>[color=darkred]
                              >>>On Mon, 12 Jul 2004 13:49:21 -0500, Piotr Wolski <wolski@cs.purd ue.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.[/color]
                              >>
                              >>i changed permissions to my compiled C programms: +rwx and nothing changed:([/color]
                              >
                              >
                              > 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).
                              >
                              >[/color]

                              the programm is example in directory 'example' so the path is
                              'example/program', example and the programm have the same full permissions..

                              Comment

                              Working...