我有一个愚蠢的问题,但我无法解决。我必须从php运行python脚本,然后使用以下命令:
$output=shell_exec("python/Users/leonardo/Sites/ema/server/sqlConnector.py. $user." ".$pass." 2>&1");
但在python中,如果我这样做:
print sys.argv
两个参数之一具有圆括号似乎无效。如果删除括号,则执行命令
例如
$output=shell_exec("python/Users/leonardo/Sites/ema/server/sqlConnector.py myname password 2>&1");
#print
['"python/Users/leonardo/Sites/ema/server/sqlConnector.py myname password 2>&1"', 'myname', 'password']
但是
$output=shell_exec("python/Users/leonardo/Sites/ema/server/sqlConnector.py myname pass(word) 2>&1");
#doesn't print anything
答案 0 :(得分:1)
您需要使用escapeshellarg()
$user = escapeshellarg($user);
$pass = escapeshellarg($pass);
$output=shell_exec("python/Users/leonardo/Sites/ema/server/sqlConnector.py $user $pass 2>&1");