我在运行php程序时遇到了一些问题。每当我在命令行中运行程序时,都会创建正确的文件,并且完美地工作。但是,当我去,并把它放在我的PHP和使用exec()函数,没有任何反应。如何在php中运行命令行功能
在我希望用户能够选择他想要的外部程序运行参数结束,但现在我只是想与....
这里硬编码值运行是我用来从命令行及其参数运行程序的命令。
[path1] -p blastp -d [parameter1] -i [path2] -e [parameter2] -m 9 -o [path3]
where [path1] is the path to ../blast-2.2.26/bin/blastall,
[path2] is the path to sample.fasta
[path3] is the path for the output file (you may want to create another folder for generating the output)
[parameter1] is the name of database chosen by the user from your page (eg. Human.db, Viruses.db, etc)
[parameter2] is the E-value given by the user from your page(eg. 0.0001, 1, 1000, etc)
实际的代码,我会键入到命令行是
~/blast/blast-2.2.26/bin/blastall -p blastp -d db -i ~/temp/sample.fasta -m 9 -o output'
这里是我到目前为止的代码。
<form method="POST", action="/~cs4380sp15grp4/home/blast.php">
<select id="database" name="database">
<option selected="selected" disabled="disabled">Database</option>
<option value="Archaea">Archaea</option>
<option value="Bacteria">Bacteria</option>
</select>
<select id="evalue" name="evalue">
<option selected="selected" disabled="disabled"> evalue <option>
<option value="0.0001">0.0001</option>
<option value="0.001">0.001</option>
</select>
<select id="hits" name="hits">
<option selected="selected" disabled="disabled"> Hits</option>
<option value="50">50</option>
</select>
<input id="BlastSearch" type="text" name="BlastSearch" value='' />
<input type="submit" name="submit" value="submit" />
<button type="reset" value="Clear">Clear</button>
</form>
<?php
session_start();
require_once '../secure/database.php';
$mysqli = new mysqli($dbhost,$dbuser,$dbpass,$dbname);
if($mysqli->connect_error){
exit('CON Error: ' . $mysqli->connect_errno . ' ' . $mysqli->connect_error);
}
//Insert the values into the database
if(isset($_POST['submit'])){
$db = $_POST['database'];
$evalue = $_POST['evalue'];
$sequence = $_POST['BlastSearch'];
$mysqli->query("INSERT INTO `Job` (`uid`, `input`, `status`, `start_time`, `finish_time`) VALUES ('1', '" . $sequence . "', 'running' , NOW(), NULL)");
$mysqli->query("INSERT INTO `BLAST`(`database`, `evalue`, 'job_id') VALUES ('" . $db . "','" . $evalue . "', `1`)") or die(mysqli_error($db));
exec(' /students/groups/cs4380sp15grp4/blast/blast-2.2.26/bin/blastall -p blastp -d db -i /students/groups/cs4380sp15grp4/temp/sample.fasta -m 9 -o /students/groups/cs4380sp15grp4/temp/output');
}
// print "Connected! Host info: " . $mysqli->host_info . "<br>\n";
$mysqli->close();
?>
所以我的执行功能是不是在我的PHP页面工作,因为相同的命令在终端工作。
您是以谁的身份运行服务器?你从命令行运行你的代码是谁? 〜/ blast/blast-2.2.26/bin/blastall的权限和所有权是什么? – Michas
我拥有正确的权限 – IloveCODE
一旦该命令在PHP内部运行,而这又是在Web服务器内部运行的,它不是*你需要权限,而是* Web服务器*。由于这看起来像一个共享的大学系统,所以可能还有其他安全配置。你有没有试过运行一个非常简单的命令,只是为了证明'exec'完全可以工作? (调试的第一个提示:为了消除问题而解决问题,这里发布的代码在'exec'行之外有很多东西,大概是 - 与这个问题无关,脱掉它!) – IMSoP