简体   繁体   English

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

[英]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.

相关问题 在批处理文件中调用php.exe时要进行参数处理 - Make an argument when calling php.exe in a batch file 用 php.exe 执行 php 文件 - execute php file with php.exe &#39;“php.exe”&#39;无法识别为内部或外部命令,可运行程序或批处理文件 - '“php.exe”' is not recognized as an internal or external command, operable program or batch file &#39;php.exe&#39; 不是内部或外部命令,也不是可运行的程序或批处理文件 - ‘php.exe’ is not recognized as an internal or external command, operable program or batch file 有没有办法用php.exe和友好的gui运行php文件? - Is there any way to run a php file with php.exe and a friendly gui? 当我在 Windows 上运行 composer 时,我收到一个错误“php.exe”不是内部或外部命令、可运行程序或批处理文件。 - When I run composer on Windows, I get an error of 'php.exe' is not recognized as an internal or external command, operable program or batch file.' 如何查看或将php.exe的stdout重定向到文件? - How to view or redirect php.exe's stdout to a file? 该操作无法完成,因为该文件已在php.exe中打开 - The action cannot be completed because the file is open in php.exe Azure Webjobs和php.exe - Azure Webjobs and php.exe 直接使用php.exe运行PHP脚本 - Running PHP scripts directly with php.exe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM