wanna execute a bin proggy and get result

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

    wanna execute a bin proggy and get result

    Problem:
    In PHP, need to execute a program in (freebsd terms) /usr/local/bin
    in meta-terms:
    int i;
    i = [execute command](arguments);

    There seems to be quite a few execution methods in PHP
    (sorry in advance for being thick), and, er, I was
    wondering if someone could give me a quick pointer
    to appropriate ones I should study to:

    1. execute a command and wait till it finishes
    2. enable a bunch of arguments to be sent to it
    3. receive an integer from the completion of that command
    {i.e. if the command is in C++,
    which it will be, then it returns from and exit(interger) }.
    Maybe, as a bonus,
    4. timeout if the command does not return

    Its a lot to ask, but from what I see so far in PHP
    (and I am becoming a fan) then I reckon it can be done.

    Many thanks, tom

  • CountScubula

    #2
    Re: wanna execute a bin proggy and get result

    "tom" <test@nospam.co m> wrote in message
    news:btbcei$igp $1$8300dec7@new s.demon.co.uk.. .[color=blue]
    > Problem:
    > In PHP, need to execute a program in (freebsd terms) /usr/local/bin
    > in meta-terms:
    > int i;
    > i = [execute command](arguments);
    >
    > There seems to be quite a few execution methods in PHP
    > (sorry in advance for being thick), and, er, I was
    > wondering if someone could give me a quick pointer
    > to appropriate ones I should study to:
    >
    > 1. execute a command and wait till it finishes
    > 2. enable a bunch of arguments to be sent to it
    > 3. receive an integer from the completion of that command
    > {i.e. if the command is in C++,
    > which it will be, then it returns from and exit(interger) }.
    > Maybe, as a bonus,
    > 4. timeout if the command does not return
    >
    > Its a lot to ask, but from what I see so far in PHP
    > (and I am becoming a fan) then I reckon it can be done.
    >
    > Many thanks, tom[/color]


    $res = `/usr/local/bin/cmd_to_execute param1 param2`;

    $res will be a string of stdout



    --
    Mike Bradley
    http://www.gzentools.com -- free online php tools


    Comment

    • Dan Tripp

      #3
      Re: wanna execute a bin proggy and get result

      CountScubula wrote:[color=blue]
      > "tom" <test@nospam.co m> wrote in message
      > news:btbcei$igp $1$8300dec7@new s.demon.co.uk.. .
      >[color=green]
      >>Problem:
      >> In PHP, need to execute a program in (freebsd terms) /usr/local/bin
      >> in meta-terms:
      >> int i;
      >> i = [execute command](arguments);
      >>
      >> There seems to be quite a few execution methods in PHP
      >> (sorry in advance for being thick), and, er, I was
      >> wondering if someone could give me a quick pointer
      >> to appropriate ones I should study to:
      >>
      >>1. execute a command and wait till it finishes
      >>2. enable a bunch of arguments to be sent to it
      >>3. receive an integer from the completion of that command
      >> {i.e. if the command is in C++,
      >> which it will be, then it returns from and exit(interger) }.
      >>Maybe, as a bonus,
      >>4. timeout if the command does not return
      >>
      >>Its a lot to ask, but from what I see so far in PHP
      >>(and I am becoming a fan) then I reckon it can be done.
      >>
      >>Many thanks, tom[/color]
      >
      >
      >
      > $res = `/usr/local/bin/cmd_to_execute param1 param2`;
      >
      > $res will be a string of stdout
      >
      >
      > --
      > Mike Bradley
      > http://www.gzentools.com -- free online php tools
      >
      >[/color]


      It's important to note that those are *backticks*. Single quotes would
      dump the line as a string into $res. Also, if safe mode is enabled,
      then the backtick operator won't work. It'd probably be better to use
      exec().

      *nix: $res = exec("/usr/local/bin/cmd_to_execute param1");
      - or -
      Windows: $res = exec("c:\somewh ere_in_the_syst em_path\foo.exe param1");

      Good notes 'bout the backtick (and a couple of samples):

      exec():


      The documentation at php.net just rocks... if you have a good idea of
      what you're looking for is called. =)

      Warm regards,

      - Dan

      Comment

      • Chung Leong

        #4
        Re: wanna execute a bin proggy and get result

        In regards to (4), there's no good way to do it in PHP.

        Uzytkownik "tom" <test@nospam.co m> napisal w wiadomosci
        news:btbcei$igp $1$8300dec7@new s.demon.co.uk.. .[color=blue]
        > Problem:
        > In PHP, need to execute a program in (freebsd terms) /usr/local/bin
        > in meta-terms:
        > int i;
        > i = [execute command](arguments);
        >
        > There seems to be quite a few execution methods in PHP
        > (sorry in advance for being thick), and, er, I was
        > wondering if someone could give me a quick pointer
        > to appropriate ones I should study to:
        >
        > 1. execute a command and wait till it finishes
        > 2. enable a bunch of arguments to be sent to it
        > 3. receive an integer from the completion of that command
        > {i.e. if the command is in C++,
        > which it will be, then it returns from and exit(interger) }.
        > Maybe, as a bonus,
        > 4. timeout if the command does not return
        >
        > Its a lot to ask, but from what I see so far in PHP
        > (and I am becoming a fan) then I reckon it can be done.
        >
        > Many thanks, tom
        >[/color]


        Comment

        • CountScubula

          #5
          Re: wanna execute a bin proggy and get result

          http://www.gzentools.com -- free online php tools
          "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
          news:ct2dneSwuf uBnWeiRVn-hQ@comcast.com. ..[color=blue]
          > In regards to (4), there's no good way to do it in PHP.[/color]

          you could possibly try wrapping the call in another php script that your
          main one calls, and do a set time put to that script.

          just a thought, not tested, so, it a theory ;)

          --
          Mike Bradley



          Comment

          Working...