Jump to content


Photo

Executing Run/CMD commands with PHP


  • Please log in to reply
5 replies to this topic

#1 ven0m

ven0m
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 October 2006 - 04:32 PM

Hey guys. Here's the thing, i'v decided to experiment a bit, and create a mini version of you tube, just for the sake of it, to understand how it works. Now, the basic idea, is for the script to convert video files into FLV files, and stream them. As far as i understood, the way to do that, is using FFMPEG and a command, which should be ran through CMD - ffmpeg -i file.avi file.flv

The question is - how do i get PHP script to execute it for me?
As far as i understood, it's done with one of several functions - exec or system.
Can anybody help me out please?

I'v tried running the following script:

<?php
  $cmd = "ipconfig";
  system($cmd,$return_value);
  ($return_value == 0) or die("returned an error: $cmd");
?>

But for some reason, it just wont run, causing the browser to stop at some point, while loading


#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 30 October 2006 - 04:36 PM

Without specifying an absolute path, the command may not be found. What's your OS? Try something universal such as "ls" on Unix or "dir" on Windows.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 ven0m

ven0m
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 October 2006 - 04:51 PM

WINXP

Ok, i'v tried dir, and it worked. now i am trying to run the following
<?php
  $cmd1 = "cd F:\software\ffmpeg";
  system($cmd1,$return_value1);
  ($return_value1 == 0) or die("returned an error: $cmd1");

  $cmd2 = "F:";
  system($cmd2,$return_value2);
  ($return_value2 == 0) or die("returned an error: $cmd2");

   $cmd3 = "ffmpeg -i 002.mpg 005.flv";
  system($cmd3,$return_value3);
  ($return_value3 == 0) or die("returned an error: $cmd3");
?>

It goes through the first/second parts and dies on the third. Is there a way to see what cmd returns?


#4 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 30 October 2006 - 05:03 PM

The second system does not see/inherit the changes of the first because it is executed in a different shell (in Unix any way). I'm not sure how Windows separates commands; in Unix it would be "cd /directory; command", which executes both commands within the same shell, and thus allows the cd to affect the command. Either do the same in Windows, or again, use full paths. Also, backslashes are special in strings--see the Windows examples in the documentation for system.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#5 ven0m

ven0m
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 30 October 2006 - 05:11 PM

I am not a mighty dos pro, so my next question is - how can i run everything with one command in CMD?

#6 mjlogan

mjlogan
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 30 October 2006 - 05:14 PM

Use the single command line to run a batch file.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users