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

时间:2013-05-15 09:33:57

标签: php windows parameters 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而不是脚本),也会出现同样的问题。

关于为什么会发生这种情况的任何想法?

1 个答案:

答案 0 :(得分:0)

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

相关问题