How do you run a command line program (like lame or svn) with PHP?

穿精又带淫゛_ 提交于 2020-01-05 05:42:44

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/2304736/how-do-you-run-a-command-line-program-like-lame-or-svn-with-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!