exec()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Austin

    #16
    Re: exec()

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

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

    Comment

    • Michael Austin

      #17
      Re: exec()

      Michael Austin wrote:

      <snippage>[color=blue]
      >
      > 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.
      >[/color]

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

      Comment

      • Piotr Wolski

        #18
        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]

        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.

        Comment

        Working...