如何使用 PHP 运行命令行程序(如 lame 或 svn)?
具体来说,我需要使用 LAME 自动将音频文件编码为 mp3。你不需要知道 LAME 来回答这个问题,我可能正在谈论 svn 或其他一些程序。
我知道如何在命令行上使用 LAME 来执行此操作,一次针对一个文件。
不过,我想通过 php 脚本来完成此操作,这样我就可以一次转换一堆文件(例如,目录中的所有文件),
所以我感到困惑的是,我应该如何调用程序 LAME。我绝对可以使用 shell_exec() http://php.net/manual/en/function.shell-exec。 php
但这是一种“扭曲”的方式吗,因为我正在通过外壳程序?
我应该以某种方式使用 lame_enc.dll 而不是 lame.exe 吗?
看来我也可以用 exec() 来做到这一点 http://php.net /manual/en/function.exec.php
但在这种情况下,我将如何提供参数?
或者有更好的方法来做到这一点,也许是 .bat 文件?我正在运行 Windows
我应该以某种方式使用 lame_enc.dll 而不是 lame.exe 吗?
Specifically, I need to automate the encoding of audio files into mp3 with LAME. You don't need to know LAME to answer this, I could be talking about svn or some other program..
I know how to use LAME on the command line to do this, for one file at a time.
I would like to do this via a php script however, so I can convert a bunch at once (for instance, all the files in a directory)
So what I am confused about, is how I should invoke the program, LAME. I could definitely use
shell_exec()
http://php.net/manual/en/function.shell-exec.php
But is that a "screwy" way to do it, since I am going through the shell?
Should I be using lame_enc.dll somehow instead, instead of lame.exe?
It seems like I could somehow do it with exec() also http://php.net/manual/en/function.exec.php
But in that case, how would I supply the arguments?
Or is there a better way to do it, maybe a .bat file? I am running windows
Should I be using lame_enc.dll instead of lame.exe somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 exec() 并指定参数,就像在命令行上一样。 PHP 程序执行手册页中概述了其他选项。
You can use
exec()
and specify arguments just like you would on the command line. Other options are outlined on the Program Execution manual page for PHP.可以用 PHP 来完成。这不是典型的用例场景,但可以做到。由于您使用的是 Windows,bat 文件会更适合,因为这样您就不需要 PHP 解析器来运行脚本。
将您在控制台中运行的相同命令放入 *.bat 中,以使用 LAME 转换音频文件。然后像运行常规可执行文件一样运行该bat。
It's possible to do it with PHP. Not a typical use case scenario but it can be done. Since you are on Windows, a bat file would be better suited since then you don't need the PHP parser to run the script.
Put the same commands you would run in the console to convert your audio files with LAME in a *.bat. Then run the bat as if it was a regular executable file.