简体   繁体   English

将参数传递到bat文件,然后将其传递到php脚本

[英]Passing parameters to a bat file and then passing them to a php script

I having trouble passing command line parameters, that were passed to a bat file, onto a php script 我在将传递到bat文件的命令行参数传递到php脚本时遇到麻烦

This is what I have: 这就是我所拥有的:

@echo off
echo %1%
set foo=%1%
php %~dp0%myscript.php %1% %2% %3%

The first three lines work. 前三行有效。 The 4th line works if it is just: 第四行仅适用于:

php %~dp0%myscript.php

also works if I hard code the parameters: 如果我对参数进行硬编码,也可以使用:

php %~dp0%myscript.php a b c

but if it is: 但如果是:

php %~dp0%myscript.php %1% %2% %3%

I get the following error: 我收到以下错误:

Could not open input file: c:\dev\123

I have tried all of the following syntax for the parameters: 我已经尝试过以下所有参数语法:

%1
%1%
"%1"
"%1%"
%*
%*%
"%*"
"%*%"

What am I doing wrong? 我究竟做错了什么?

Never mind figured it out: 没关系弄清楚了:

set pth=%~dp0%myscript.php
php %pth% %1 %2 %3

seems I have to do it in two steps - looks as if too much concatenation is confusing it. 似乎我必须分两个步骤进行操作-似乎太多的连接使它感到困惑。

There are evil superabundant % percent signs in your line: 您的行中有邪恶的多余%百分号:

php %~dp0%myscript.php %1% %2% %3%
         ^               ^   ^   ^

This line is then parsed as follows: 然后按以下方式分析此行:

  • php :taken literally; php :从字面上看;
  • %~dp0 :results to full path of your bat or cmd script; %~dp0 :导致batcmd脚本的完整路径;
  • %myscript.php % : results to empty string; %myscript.php % :结果为空字符串;
  • 1% %2% %3% : results to 123 as every % % results to empty string and trailing % as well. 1% %2% %3% :结果为123因为每% %结果为空字符串,尾随%结果也为空。

As per Command Line arguments (Parameters) , use 根据命令行参数(Parameters) ,使用

php %~dp0myscript.php %1 %2 %3

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

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