[英]php.exe script parameters in batch file
I'm trying to execute a PHP script on Windows through php.exe, while passing parameters to the script. 我正在尝试通过php.exe在Windows上执行PHP脚本,同时将参数传递给脚本。 Everywhere I look, it says it should work like this:
我到处看,它说应该这样工作:
php -f "path\to\my\script.php" -- -t 10 -i 5
The -t 10 -i 5 should be passed to script.php, where I can access them through $argv. -t 10 -i 5应该传递给script.php,在这里我可以通过$ argv访问它们。 When I type this in on the command line, everything runs as expected.
当我在命令行中键入此命令时,一切都会按预期运行。 When I paste the very same line in a .cmd file, the part after script.php gets treated as a seperate command.
当我将同一行粘贴到.cmd文件中时,script.php之后的部分将被视为单独的命令。 (and yes, it is a single line in the batch file)
(是的,它是批处理文件中的一行)
C:\>php -f "path\to\my\script.php" -- -t 10 -i 5
<<<output of the php script as expected>>>
C:\>mybatch.cmd
C:\>php -f "path\to\my\script.php"
<<<output of the php script not receiving the parameters>>>
C:\>-- -t 10 -i 5
'--' is not recognized as an internal or external command, operable program or batch file.
I first thought it might be a problem with the --, but even if I leave out the -- (basically passing the other parameters to php.exe instead of to the script), the same problem occurs. 我最初以为-可能是一个问题,但是即使我省略了-(基本上将其他参数传递给php.exe而不是脚本),也会出现相同的问题。
Any ideas on why this is happening? 为什么会这样?
Found the problem, appearantly there was a linefeed after the filename of the script, but that was not visible in notepad. 找到了问题,脚本的文件名后面似乎有一个换行符,但是在记事本中不可见。 No idea how it got there (probably copy/paste related), but removing it fixed the problem.
不知道它如何到达那里(可能与复制/粘贴有关),但是删除它可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.