0

我想通过 PHP 运行它exec

./text2speech.sh "My name is Oscar and I am testing the audio."

下面是我的代码。如何在""不干扰 PHP 的情况下发送?

<?php

function doSomething($command) {
    exec("./text2speech.sh". " $command", $output);
    echo "Returned output:";
    var_dump($output);
} 

if(count($_POST) > 0 && isset($_POST['command'])) {
    doSomething($_POST['command']); 
}

?>
<!DOCTYPE html>

<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">

<title>Terminal Emulator</title>
</head>

<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
    <input autocomplete="off" id="command" name="command" type="text">
    <input type="submit" value="Submit">
</form>

</body>
</html>
4

2 回答 2

0

试过:

...
$call = "./text2speech.sh" . "\"" . $command . "\"";
exec($call, $output);
...

或全部在一条线上

exec("./text2speech.sh \"$command\"", $output);

没试过这个,但$call应该等于 './text2speech.sh "command text here" '

于 2013-08-20T13:42:44.450 回答
0

我想你会想逃避引号:

exec("./text2speech.sh \"$command\"", $output);

或使用单外引号代替:

exec('./text2speech.sh "' . $command . '"', $output);

顺便说一句,<body>如果要显示输出,最好将 PHP 代码放入该部分。

于 2013-08-20T13:43:37.533 回答