79455466

Date: 2025-02-20 18:16:09
Score: 1
Natty:
Report link

In trying to execute this command in both windows and unix I had issues. I could get one to work but then the solution stopped the other from working.

Unix php ../../folder/file.php "a=10&b=20" works in cmd line Wnds php H:\folder1\folder2/folder/file.php "a=10&b=20" works in cmd line

but from within php script shell_exec would remove space between cmd and args. so cmd would look like php "../../folder/file.php""a=10&b=20" and would fail.

Solution add a '%' to the command $cmd = 'php '.escapeshellarg("../../folder/file.php").' % "a=10&b=20"';

The '%' allowed the space to remain in the cmd and the file.php had one line of code to str_replace('%','',$argv[1]) to remove it.

BTW I use this technique so that the file.php can be called either from web url or cmd line...

if (!isset($_GET['a'])) parse_str(implode('&',array_slice($argv, 1)),$_GET);

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Dave Joyce