Jump to content

shell_exec background process.


RuleBritannia
Go to solution Solved by requinix,

Recommended Posts

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

Link to comment
Share on other sites

& 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 by RuleBritannia
Link to comment
Share on other sites

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 by requinix
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.