RuleBritannia Posted November 11, 2013 Share Posted November 11, 2013 Hello I seem to have tried many combinations to get this process to run in the background, but it doesnt. shell_exec('C:\ffmpeg -y -i "C:\2.avi" -preset veryslow -crf 25 "C:\2.mkv" 1>output.log 2>error.log &'); Tried to redirect error to error.log, output to output.log, and & to run in the background, This does not work because the php script waits for it to finish. I have tried many variations of this code(swapping locations of 1< 2<, removing "1" from 1<) etc Also tried this shell_exec('C:\ffmpeg -y -i "C:\2.avi" -preset veryslow -crf 25 "C:\2.mkv" <input.log 1>output.log 2>error.log &'); this should direct input to a input.log file, But this causes the whole script to not even work. Anybody had any experience with this function? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted November 11, 2013 Solution Share Posted November 11, 2013 & does not work on Windows. if (strncasecmp(PHP_OS, "Win", 3) == 0) { $com = new COM("WScript.Shell"); $com->Run('C:\ffmpeg ...', 0, false); } else { shell_exec('ffmpeg ... &'); } Quote Link to comment Share on other sites More sharing options...
RuleBritannia Posted November 11, 2013 Author Share Posted November 11, 2013 (edited) & does not work on Windows. if (strncasecmp(PHP_OS, "Win", 3) == 0) { $com = new COM("WScript.Shell"); $com->Run('C:\ffmpeg ...', 0, false); } else { shell_exec('ffmpeg ... &'); } Thanks alot that seemed to have worked, Saved me alot of time. I have been reading the MSDN notes and php on the COM class, but it does not give me info in regards to Run and returning output I tried to reuse what was working in my previuos code 2>&1 Would return results in a variable. or 1>output.log 2>error.log would return results in those log files. This no longer works, do you know a replacement? Thanks Edited November 11, 2013 by RuleBritannia Quote Link to comment Share on other sites More sharing options...
RuleBritannia Posted November 11, 2013 Author Share Posted November 11, 2013 For those interested I managed to find a way to get the ouput or error etc. Instead of just $com->Run('$command', 0, false); Use $com->Run('cmd /C $command', 0, false); It still maybe possible to do in the first, but I couldnt get it to work after trying many variations. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 11, 2013 Share Posted November 11, 2013 (edited) WScript.Shell.Run is documented over here. Runs a program in a new process. object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) Arguments object: WshShell object [which is the WScript.Shell you have in $com] strCommand: String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file. intWindowStyle: Optional. Integer value indicating the appearance of the program's window. Note that not all programs make use of this information. bWaitOnReturn: Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code). ... Remember that you're running this in the background: you can't get the output "now" because the command hasn't finished executing, and even if you redirect output to a file (which is how you'd do it here) you can't get it in the next couple statements because the command still hasn't finished executing. That's the downside to running in the background so reconsider whether you actually want to do that. As for output redirection, yes it seems you need cmd /c - I thought it was run inside cmd anyways but apparently not. cmd /c C:\ffmpeg ... 1>output.log 2>error.log Edited November 11, 2013 by requinix Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.