SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    The exec() function

    Hi everyone,

    If I have a PHP script like this:

    PHP Code:
    exec('command 1');
    exec('command 2');
    exec('command 3'); 
    When will commands 2 and 3 execute? Will command 2 execute after command 1 has completed, or after command 1 has started executing?

    Sam

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    From The Manual
    If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
    So, unless you specify the output as another file or stream, it will execute 1 then 2 then 3. Otherwise it'd thread them all.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Must have missed that bit when I read that page earlier, oops.

    Any idea how to go about redirecting the output to another file?

  4. #4
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    exec('command 1 > /dev/null');
    or
    exec('command 1 > /home/user/text.txt');

    code gpl licensed.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will give that a try. Thanks!

    Edit: got this to work perfectly. Thanks a bunch guys.
    Last edited by SJH; Nov 17, 2008 at 14:14.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •