shell_exec无法正常工作,可能是因为特殊字符

问题描述 投票:0回答:1

我有一个命令,我想从PHP运行

$shell = 'mysqldump -uuser -ppass --where="id>' . $larger .' and id<' . $smaller .'" view allasins | gzip -c | sshpass -p "pass2" ssh [email protected]  \'cat>/home/user/domain.com/file.sql.gz\'';
$shell = escapeshellarg($shell); //this is not working, escapeshellcmd($shell) also not working
shell_exec($shell);

那么,有谁知道这些代码有什么问题?没有错误消息,它根本不起作用。

非常感谢你。

php special-characters shell-exec
1个回答
1
投票

尝试使用

escapeshellcmd所以:

$Command = escapeshellarg($shell);

用途

escapeshellarg()

是逃避单个字符串,因为它在你的例子中工作:

$shell = 'mysqldump -uuser -ppass --where="id>' . escapeshellarg($larger) .' and id<' . escapeshellarg($smaller) .'" view allasins | gzip -c | sshpass -p "pass2" ssh [email protected]  \'cat>/home/user/domain.com/file.sql.gz\'';
© www.soinside.com 2019 - 2024. All rights reserved.