exec("lame audio.mp3 audio.wav")
Similar questions didn't helped.
This is the command that should be executed via PHP.
The audio.mp3 file presents in the directory and no permission issues.
Lame encoder is present at: C:\Program Files (x86)\Lame. This path is added into System Environmental Variables PATH.
lame command works in cmd, it displays the version as 3.99.3. (This means lame is installed and added to the PATH properly).
The PHP file present in the folder D:\XAMPP\htdocs\demo.php. Executing lame audio.mp3 audio.wav via cmd in the directory D:\XAMPP\htdocs runs properly and the mp3 file is converted to wave file without any issue.
The PHP exec is alone not working. Where I am missing?
Edit: The error.log file have the following error:
'lame' is not recognized as an internal or external command, operable
program or batch file.
Related
Im trying to install Composer.exe, and it always fail after I choose php.exe file and click next, with an error:
The PHP exe file you specified did not run correctly [exit code 1]: D:\Software(x86)\wamp64\bin\php\php7.0.10\php.exe
Program Output: 'D:\Software' is not recognized as an internal or external command, operable program or batch file.
Thing is: Path to the php.exe is valid. I have php in env variables, so if I run cmd and type in php it runs...
But if open cmd and type in path that I gave to the composer so D:\Software(x86)\wamp64\bin\php\php7.0.10\php.exe
It respond with 'D:\Software' is not recognized as an internal or external command, operable program or batch file. too.
To clarify, I restarted computer after php installation and I after added env variables.
And this is in my env path var: ...;D:\Software(x86)\wamp64\bin\php\php7.0.10\
I installed xampp on D:\ Drive and it didnt work too, then I
uninstalled it and istalled it on C:\ and it worked... Dunno what was
the problem, if someone can explain, please do. Thanks
I guess you have to escape the braces in windows. Either with a backslash or the complete folder with quotes
To install Composer in my shared host, I ran from my home directory:
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Then I was told to run: $ php bin/composer.phar
And following that I was able to use Composer, confirmed by running:
$ composer.phar -V
Composer version 1.0-dev
Can someone please explain the command php bin/composer.phar?
Is it simply telling php to unpack the .phar file? If so, where does it unpack it to? I see bin/bin/composer.phar* after having run it. Then I have to run composer using the entire path to the phar file, unless I'm in the home directory.
A .phar file is a ZIP-like file that contains all the files that make up a PHP application, and some initial code in the file header that sets up some stuff and then transfers execution to the first zipped file.
The command php bin/composer.phar is calling PHP and gives the phar file as a parameter to make PHP execute that file. This will make PHP read that file, find the header with the bootstrapping code and execute that. PHP will initialize PHAR execution and go further into that compressed file.
The command composer.phar will only work if that file has been marked with the x file flag to make it executable, and it is placed in a directory that is mentioned in the $PATH environment variable. Part of the PHAR file is the first line of the file header that is called "shebang". This line is used in all script files for the command line to specify the interpreter that should be used to execute the file. In case of composer.phar, this interpreter is PHP. So in essence, the same thing happens as with the first call: PHP is "running" the PHAR file, but with less typing on the command line.
I'm currently experimenting with WP-CLI (http://wp-cli.org) - I have finally managed to get it to run on my basic command line by downloading/moving it to a PATH variable directory (i.e C:\xampp\php) and then updating my PATHSPEC to include .PHAR.
I have renamed the original file from wp-cli.phar to wp.phar in order to be able to reference it as wp in my cmd.exe.
Prior to this method I installed wp-cli using CURL and chmod in my Git Bash installation then renaming the file to wp (without an extension) and adding the path containing file to the PATH variable. This caused the .PHAR file to work in Git Bash but not to work on the command line.
MY ISSUE:
Whenever I try to use my wp.phar in the native CLI I get a php error report - it does recognise the command and does show a list of suggestions (which is usually given when syntax is incomplete or incorrect).
How do I even start to figure this out?
1 - I've attempted to look for a git batch file in my Git Bash directory to see if I can find a dependency I'm missing but no dice.
2 - My Git Bash is now not recognizing the wp command and I now need to refer to wp.pharand then add any sub-commands/arguments after. However using the Git Bash CLI wp.phar doesn't cause errors
After a few months I found a solution.
Make sure that your PHP root folder path and the folder path containing your phar files are added to the Windows PATH Environment Variable (to allow us to just use the filename to refer to them).
CMD Line Options (Run as Administrator):
assoc .php=phpfile and assoc .phar=pharfile
Next is adding the program that opens this file. Adding an ftype command allows us to open .php/.phar files without using the php.
ftype pharfile=php.exe %1 %* (The %1 is a placeholder for the file called and %* refers to any other arguments that many be input).
FINALLY
The key issue was getting the .phar scripts to execute in the command line as windows ends up trying to open these files in it's Open With Dialog
So what I did was wrap my .phar in a batch file with this command (in the same folder as the phar
echo php "%~dp0wp-cli.phar" %* > [name of file].cmd
I then run this file as [name of file] with any arguments and it works as usual.
I'm using PHP 5.5.6 and trying to use exec() to execute the gitolite binary that is located in /usr/libexec/gitolite/gitolite and is symlinked from /usr/bin/gitolite to that binary.
I am able to run other commands (such as id) that are located in /usr/bin/. If I copy or hardlink the binary to /usr/bin/gitolite, it also works just fine. But when it's symlinked to /usr/libexec/gitolite and I include 2>&1 at the end of the command string passed to exec(), the output is
sh: find: command not found
It seems to me like there's a readlink going on somewhere and it sees that /usr/libexec/gitolite is not in some allowed list of directories, but the safe_mode_exec_dir configuration directive doesn't exist in PHP 5.5.
For what it's worth, this is running in Apache 2.4.6.
How can I run a PHP script from the command line using the PHP interpreter which is used to parse web scripts?
I have a phpinfo.php file which is accessed from the web shows that German is installed. However, if I run the phpinfo.php from the command line using - php phpinfo.php and grep for German, I don't find it. So both PHP files are different. I need to run a script which the php on which German is installed.
How can I do this?
You should check your server configuration files. Look for lines that start with LoadModule php...
There probably are configuration files/directories named mods or something like that. Start from there.
You could also check output from php -r 'phpinfo();' | grep php and compare lines to phpinfo(); from web server.
To run php interactively:
(So you can paste/write code in the console.)
php -a
To make it parse a file and output to the console:
php -f file.php
Parse a file and output to another file:
php -f file.php > results.html
Do you need something else?
To run only a small part, one line or like, you can use:
php -r '$x = "Hello World"; echo "$x\n";'
If you are running Linux then do man php at the console.
If you need/want to run PHP through fpm (FastCGI Process Manager), use cli fcgi:
SCRIPT_NAME="file.php" SCRIP_FILENAME="file.php" REQUEST_METHOD="GET" cgi-fcgi -bind -connect "/var/run/php-fpm/php-fpm.sock"
Where /var/run/php-fpm/php-fpm.sock is your php-fpm socket file.
On SUSE Linux, there are two different configuration files for PHP: one for Apache, and one for CLI (command line interface). In the /etc/php5/ directory, you will find an "apache2" directory and a "cli" directory. Each has a "php.ini" file. The files are for the same purpose (PHP configuration), but apply to the two different ways of running PHP. These files, among other things, load the modules PHP uses.
If your OS is similar, then these two files are probably not the same. Your Apache php.ini is probably loading the German module, while the the CLI php.ini isn't. When the module was installed (auto or manual), it probably only updated the Apache php.ini file.
You could simply copy the Apache php.ini file over into the cli directory to make the CLI environment exactly like the Apache environment.
Or, you could find the line that loads the German module in the Apache file and copy/paste just it to the CLI file.
I was looking for a resolution to this issue in Windows, and it seems to be that if you don't have the environment variables ok, you need to put the complete directory. For example, with a file in the same directory as PHP:
F:\myfolder\php\php.exe -f F:\myfolder\php\script.php