January 21st, 2014, 06:32 PM
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.
January 21st, 2014, 07:54 PM
I see you tell it to run "ffmpeg" in whatever the current folder is... Maybe the command can't find ffmpeg?
When in doubt,
error_reporting = -1
display_errors = on
January 21st, 2014, 08:00 PM
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.
January 22nd, 2014, 12:22 AM
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.
Originally Posted by chadwyk
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
January 22nd, 2014, 01:04 AM
On that note,
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?
Originally Posted by chadwyk
January 22nd, 2014, 06:54 AM
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
January 22nd, 2014, 10:11 AM
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!