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?

1
  • Are you sure it isn't doing anything? You can probably also check process exit value -- that's $?, at least in Ruby and Perl. Commented Sep 15, 2012 at 1:52

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

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?
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?
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).
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.
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.

1 Comment

Sorry, I'm not sure what you mean. There is no output from this command, only audio.
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;

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.