简体   繁体   中英

Can't pass more than one argument using exec() PHP

given the following code:

 exec('cmd /c c:\wamp\www\Telnetshutdown.py '.$router);

the router variable is passed fine. but, given the following code:

 exec('cmd /c c:\wamp\www\Telnetshutdown.py '.$router.' '.$interface);

or

 exec('cmd /c c:\wamp\www\Telnetshutdown.py '.$router." ".$interface);

or

         $zz=$router.' '.$interface;
 exec('cmd /c c:\wamp\www\Telnetshutdown.py '.$zz);

and more combinations of those.. Does not work! How can I pass more than one argument?

Try to use escapeshellarg to make sure your arguments are properly escaped

It appears also based on this post that php will frame the argument passed to exec with cmd /c "{{exec argument}}" when passing it off to the shell.

Try this:

exec('c:\wamp\www\Telnetshutdown.py '.escapeshellarg($router).' '.escapeshellarg($interface));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM