#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0

    Shell_exec doesn't run from scheduled task


    So I created a script that runs a shell_exec command to load up FFMPEG and re-encode files.

    shell_exec("ffmpeg -i ../media/movies/toConvert/" . $filesToConvert[$x] . " ../media/movies/converted/" . $trimmed . ".mp4 1> ../media/movies/converted/" . $trimmed . ".txt 2>&1");

    I want it to run every x minutes.

    I created a batch file to execute the script.

    When I double click the .bat it runs perfectly and converts the file as expected.

    However, I setup a windows task scheduler event to run the batch file and it doesn't work correctly at all. I output text before and after the shell_exec command and it's like it skips right over it and doesn't execute it. I get no errors, its just like it is not there. Does Task scheduler not have the same permissions as if you run the bat manually? I looked and the event is set to run as my user. I don't get it.
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    I see you tell it to run "ffmpeg" in whatever the current folder is... Maybe the command can't find ffmpeg?

    When in doubt,
    Code:
    error_reporting = -1
    display_errors = on
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0
    No, I don't think that's the problem. I have ffmpeg in the system path, so you can run it from anywhere.

    When I'm back at work I'll play around more, thinking maybe it can't find the paths of the files or something silly maybe??? Just seems weird that it works perfect if you run the .bat manually, either by double clicking it, or from the command-line.
  6. #4
  7. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,905
    Rep Power
    3969
    Originally Posted by chadwyk
    No, I don't think that's the problem. I have ffmpeg in the system path, so you can run it from anywhere.
    The environment is likely to be different when running a task via the scheduler than it is when you run things manually. One of those differences may be what the PATH variable is defined as. I'm not sure how much of an issue this is for windows, but is a common problem on linux with cron.

    You should always use an absolute path to your executable files when setting up automated tasks, just to be certain that it is found and you run the correct one (in case there are multiple copies)
    Recycle your old CD's, don't just trash them



    If I helped you out, show some love with some reputation, or tip with Bitcoins to 1N645HfYf63UbcvxajLKiSKpYHAq2Zxud
  8. #5
  9. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    On that note,
    Originally Posted by chadwyk
    I have ffmpeg in the system path, so you can run it from anywhere.
    Which one? As kicken said there is more than one PATH variable: one for each account, plus the global one, and that's separate from one set temporarily (eg, in a command prompt). Does that change your reply?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,400
    Rep Power
    1688
    Also do not forget those relative pathnames you have as parameters, relative to where?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    3
    Rep Power
    0
    Thanks guys. It was a problem with the path to ffmpeg. Task scheduler must not of been able to find it.

    Hard coding the path to ffmpeg.exe was the way to go. It worked.

    The relative paths seem to not matter.

    shell_exec("c:/ffmpeg/ffmpeg.exe -i ../media/movies/toConvert/IMG_3321_2_245.mov ../media/movies/converted/IMG_3321_2_245.mp4 1> ../media/movies/converted/IMG_3321_2_245.txt 2>&1");


    I guess task scheduler uses a different path than what I had it in. It was in the system path, not the user path.. so it still confuses me but whatever.. it's working!

IMN logo majestic logo threadwatch logo seochat tools logo