2

I'm trying to run the following command from a PHP file in a web browser:

 exec('festival --tts /var/www/test.txt &');

Unfortunately, nothing happens. I thought of trying 'echo' but there is nothing to return to see if the command is working. I set permissions for test.txt to 777. I also ran the command in a shell and it works just fine - just not when submitted by a PHP script. What am I doing wrong?

Alligator
  • 43
  • 1
  • 6
  • Are you sure it isn't doing anything? You can probably also check process exit value -- that's `$?`, at least in Ruby and Perl. – Linuxios Sep 15 '12 at 01:52

3 Answers3

4

Provide the full path to the festival binary, you can find it out on the console with which festival command, then use it in your exec call, like this:

exec('/usr/bin/festival --tts /var/www/test.txt &');

Update: You need to make sure the folder where you are creating the file has write permission for the user running php which usually is www-data on debian based distros.

Nelson
  • 49,283
  • 8
  • 68
  • 81
  • I ran "which festival" and found it in "/usr/bin/festival". Unfortunately, when I add this to the PHP file, it still does not run the command. Is there a permissions error here somewhere? If so, what do I do to change it? – Alligator Sep 15 '12 at 02:34
  • Then it's probably a permission problem, what is the ouput of this command? "ls -ld /var/www" Also, which linux distro are you running this? – Nelson Sep 15 '12 at 09:36
  • 1
    That is the problem, the path to file needs to be inside a folder that is owned by the user tha runs PHP (usually www-data in debian/ubuntu distros). – Nelson Sep 15 '12 at 14:16
  • Change /var/www/test.txt for a path that is inside your DOCUMENT_ROOT and it will be ok, if you want it outside DOCUMENT_ROOT make sure you change the permission of the folder to be owned by www-data user. – Nelson Sep 15 '12 at 14:17
1

If I understand correctly what you're trying to do, you aren't returning the input. The syntax for this is:

exec('command', $output);

where $output is the variable in which the script's output will be stored. Oddly, this output will be returned as an array, so don't forget to implode() it when you're done if you're expecting a string.

Winfield Trail
  • 5,535
  • 2
  • 27
  • 43
1

Does the festival program print any output? If so, try capturing that. Also check the return value.

exec('/usr/bin/festival --tts /var/www/test.txt &', $output, $return);

Dump the output array, like so:

var_dump($output);

Any non-zero return value usually indicates an error:

echo $return;
tim berspine
  • 825
  • 1
  • 9
  • 17
  • No, the "festival" command is a text-to-speech command. There is only audio as an output. However, I tried what you wrote, and this is what was returned: array(0) { } 0 – Alligator Sep 15 '12 at 02:35