D
D
Dokuro2015-11-06 17:06:52
PHP
Dokuro, 2015-11-06 17:06:52

How to get the program's response from the console into a variable?

Hello everyone, I have a question.
There is a call to ffmpeg via the PHP passthru() function;
More precisely, I need to get information about the video in order to parse it later.
I do this for example:

$response = passthru('ffmpeg -i /home/dokuro/vedeos/60fps_FREELY_TOMORROW_-_Hatsune_Miku.mp4');

var_dump($response);

But in the end $response is NULL. But if I run the command in the terminal - I get the answer.
Also, if you execute a command, but tell it to write the answer to a file, it is written.
passthru('ffmpeg -i /home/dokuro/vedeos/60fps_FREELY_TOMORROW_-_Hatsune_Miku.mp4 2> result.txt');

How can I make it write to a variable? Is it possible?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Shorokhov, 2015-11-06
Chan @iDokuro

Use the exec()
function . It has an array of strings that the command outputs.
It is possible that the command will output one thing to the terminal, and return a slightly different one to the exec() function. In this case, try adding an output redirect to the end of the command:
ffmpeg ... 2>&1

M
Mikhail Osher, 2015-11-06
@miraage

php.net/manual/en/function.passthru.php

passthru('ffmpeg -i /home/dokuro/vedeos/60fps_FREELY_TOMORROW_-_Hatsune_Miku.mp4', $response);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question