从shell_exec传递的sys.argv变量缩短了

时间:2018-04-19 06:27:41

标签: php python shell-exec sys

当我想从php shell_exec()执行我的python脚本时,我遇到了很多麻烦,如标题所示

这是我的代码
exec.php

<?php
$my_url="http://reviews.femaledaily.com/moisturizer-36/lotions/nature-republic/aloe-vera-92-soothing-gel-06?tab=reviews&cat=&cat_id=0&age=&order=nrd&page=1";
echo shell_exec("python hello.py '".$my_url."'");
?>

hello.py

import sys
x = sys.argv[1]
print(x)

输出

'http://reviews.femaledaily.com/moisturizer-36/lotions/nature-republic/aloe-vera-92-soothing-gel-06?tab=reviews

我想要的输出

'http://reviews.femaledaily.com/moisturizer-36/lotions/nature-republic/aloe-vera-92-soothing-gel-06?tab=reviews&cat=&cat_id=0&age=&order=nrd&page=1'

这有什么解决方案吗?或者我应该把它分成两个参数?

1 个答案:

答案 0 :(得分:0)

使用escapeshellarg()正确转义命令的参数。

echo shell_exec("python hello.py " . escapeshellarg($my_url));