Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8781971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:26:52+00:00 2026-06-13T20:26:52+00:00

I have the following PHP code: <?php $video = C:\Users\Administrator\myVideo\processing\video.mp4; $cmd = ‘ffmpeg -i

  • 0

I have the following PHP code:

<?php
$video = "C:\Users\Administrator\myVideo\processing\video.mp4";
$cmd = 'ffmpeg -i "' . $video .'" 2>&1 | wtee buffer.txt'; // wtee is a Windows version of tee

exec($cmd);
echo($cmd);
?>

If I run aa.php, which contains the above code, it won’t work.

But if I run the $cmd that is being echoed out on the command prompt directly, the file buffer.txt is created and works.

I want to get the output of this:

$cmd = 'ffmpeg -i "' . $video .'"'

Into a variable like, e.g. $output.

This code, so far, prints blank:

exec($cmd,$output,$result);
print_r($output);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:26:53+00:00Added an answer on June 13, 2026 at 8:26 pm

    Like you mentioned, that your code works directly from command line but not from PHP CLI, is most likely because of log file permissions, which means, you must create a log file with correct permissions first, and then write your output there!

    For example, from command line (not PHP) make sure that you delete your log file buffer.txt and run your PHP code again. Most likely it will not work as your file doesn’t exist. Remember, when you run that command from command line directly, your log file, which is buffer.txt is created with special permissions (not only read/write, but also group and owner (Linux)). When PHP creates a file, by default, it uses nobody nobody for owner/group and you already have a log file (as you ran that same command from command line), which is created by other user (I suppose administrator), as a result you can be sure that PHP will not be able to use it, just because of the wrong file permissions. Try to see what is on your current log file owner/group by executing ls -ls in Linux or DIR /Q in Windows to get the idea.

    Besides everything, make sure that you’re not running PHP in safe mode, as a result exec might not work as you expect it, because it’s disabled if PHP is in safe mode.

    1. shell_exec() (functional equivalent of backticks)
      This function is disabled when PHP is running in safe mode.

    2. exec()
      You can only execute executables within the safe_mode_exec_dir. For practical reasons it’s currently not allowed to have components in the path to the executable. escapeshellcmd() is executed on the argument of this function.

    You can check your server’s PHP settings with the phpinfo() function.

    Your code should rather look like this:

    exec("$cmd 2>&1", $output);
    log_conversion($config['logs_path']. '/' .$video_id. '_log.txt', $cmd);
    log_conversion($config['logs_path']. '/' .$video_id. '_log.txt', implode("\n", $output));
    

    What does that mean? If you say 2>&1 then you are redirecting stderr to wherever stdout is currently redirected to. If stdout is going to the console then stderr is, too. If stdout is going to a file then stderr is as well.

    Please read more about command redirections in articles Using command redirection operators for Windows or All about redirection for Linux.

    Your log conversion function, could be something like this:

    function log_conversion($file_path, $text)
    {
        $file_dir = dirname($file_path);
        if( !file_exists($file_dir) || !is_dir($file_dir) || !is_writable($file_dir) )
            return false;
        
        $write_mode = 'w';
        if( file_exists($file_path) && is_file($file_path) && is_writable($file_path) )
            $write_mode = 'a';
        
        $handle = fopen($file_path, $write_mode);
        if( !$handle )
            return false;
        
        if( fwrite($handle, $text. "\n") == FALSE )
            return false;
        
        @fclose($handle);
    }
    

    It’s very important to make sure that the log file you create is writable and has correct permissions!

    I personally delete the log file in case it exists, to make sure that I have recent and reasonable log file.

    I bet it will work either like this or with small tweaking!

    If it doesn’t work for you, please let me know and I will elaborate!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written following PHP code: $input=menu=1&type=0&; print $input.<hr>.ereg_replace('/&/', ':::', $input); After running above
I have following PHP code $val=<div id=user.$row['cid']. userid=.$row['cid']. class=innertxt><img src=images/images.jpg width=50 height=50><strong>.$uname.</strong><ul> <li>Email: .$row['cemail'].</li>
I have the following PHP code, and for the life of me I can't
I have the following php code: $k=1; for($i=0; $i < 5; $i++) { $stmt
I have the following php code: $k=1; for($i=0; $i < 5; $i++) { $stmt
I have the following PHP Code #The facebook message $fh = fopen('comments.txt', 'r') or
I have the following PHP code // Check if the upload is setted if
I have the following php code which I want to add a delay too:
I have the following PHP code which works out the possible combinations from a
I have the following PHP code doing a very simple select into a table.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.