处理ghost space命令行php


dealing with ghost spaces command line php

当我尝试用php exec执行以下命令行指令时遇到问题:

    $instruction="mpirun -n 2 raxmlHPC-MPI ­-s ".$uploadfile." ­-p 12345 ­-m PROTGAMMAAUTO --­­auto­-prot=".$_POST["selectCriteria"]." ­-n outfile -# 2";
exec($instruction);

我打印出我想要执行的变量,它带有一些空格:

mpirun -n 2 raxmlHPC-MPI  ­-s /home/compartido1/workspace/raxml/uploaded_files/user_1449959556Alignment.fasta  ­-p 12345 ­ -m PROTGAMMAAUTO --­­ auto­ -prot=aicc  ­-n outfile -# 2

我不知道发生了什么。

我不确定额外的空间来自哪里。这很奇怪。

注意不要直接使用$_POST中的数据,也不要使用未跳过的数据。

请正确使用escapeshellcmd()。

我已经使用字符串串联重写了该命令来构建该命令。

也许这就解决了问题。请试一试。

$command = 'mpirun';
$command .= ' -n 2 raxmlHPC-MPI';
$command .= ' ­-s ' . $uploadfile;
$command .= ' -p 12345';
$command .= ' ­-m PROTGAMMAAUTO';
$command .= ' --­­auto­-prot=' . $_POST['selectCriteria'];
$command .= ' ­-n outfile';
$command .= ' -# 2';
$escaped_command = escapeshellcmd($command);
exec($escaped_command);