繁体   English   中英

批处理文件中的php.exe脚本参数

[英]php.exe script parameters in batch file

我正在尝试通过php.exe在Windows上执行PHP脚本,同时将参数传递给脚本。 我到处看,它说应该这样工作:

php -f "path\to\my\script.php" -- -t 10 -i 5

-t 10 -i 5应该传递给script.php,在这里我可以通过$ argv访问它们。 当我在命令行中键入此命令时,一切都会按预期运行。 当我将同一行粘贴到.cmd文件中时,script.php之后的部分将被视为单独的命令。 (是的,它是批处理文件中的一行)

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.

我最初以为-可能是一个问题,但是即使我省略了-(基本上将其他参数传递给php.exe而不是脚本),也会出现相同的问题。

为什么会这样?

找到了问题,脚本的文件名后面似乎有一个换行符,但是在记事本中不可见。 不知道它如何到达那里(可能与复制/粘贴有关),但是删除它可以解决问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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