在本地wamp设置的批处理文件中通过url传递php变量(Passing a php variable via url in a batch file on local wamp setup)

编程入门 行业动态 更新时间:2024-10-28 13:24:27
在本地wamp设置的批处理文件中通过url传递php变量(Passing a php variable via url in a batch file on local wamp setup)

环境:Windows 7,PHP 5.3.13,Apache 2.2.22(WAMP)本地工作访问外部Web服务

我正在尝试通过批处理命令提示符内的URL在PHP中分配一个全局变量来调用Web服务。 请参阅以下批次行:

start / b“C:\ wamp \ bin \ php \ php5.3.13 \ php.exe”-q“C:\ wamp \ www \ test \ scripts \ apiTest.php?itemID =%1”> API_Log%dtStamp%。文本

在使用实际项目ID运行此bat文件时:C:\ wamp \ www \ test \ scripts \ apiTest.bat 1234567

我收到一个未定义的索引错误,找不到匹配的404。 在检查HTTP数据包时,我注意到URL已经丢弃(从未收到)我在执行字符串中指定的itemID。 HTTP信息: http : //api.service.com/items//items.xml http://api.service.com/items/(此处为识别信息)/items.xml

我可以直接从cmd / batch访问带有参数的特定网址,我直接在网址中输入变量并在浏览器中执行此过程没有任何问题。

我怀疑将api url直接发送到php可执行文件,但是参数是不可能的。 身份证号码没有正确附加,甚至根本没有追加。 有任何想法吗?

Environment: Windows 7, PHP 5.3.13, Apache 2.2.22 (WAMP) Working locally Accessing external web service

I'm attempting to assign a global variable in PHP via URL inside of a batch command prompt to call a web service. See the following batch line:

start /b "C:\wamp\bin\php\php5.3.13\php.exe" -q "C:\wamp\www\test\scripts\apiTest.php?itemID=%1" > API_Log%dtStamp%.txt

Upon running this bat file with the actual item ID: C:\wamp\www\test\scripts\apiTest.bat 1234567

I get an Undefined Index error and matching 404 not found. Upon inspecting the HTTP packet I'm noticing the URL has dropped (never received) the itemID I've specified in the execution string. HTTP info: http://api.service.com/items//items.xml http://api.service.com/items/(missing identification info here)/items.xml

I can definitely access specific urls with arguments directly from cmd/batch and I've directly typed the variable into the url and executed this process in a browser with no problem.

I suspect sending the api url directly to the php executable WITH an argument is not possible. The id number is not appending correctly or even at all. Any ideas?

最满意答案

而不是像GET请求一样发送它,你应该使用类似的东西:

start /b "C:\wamp\bin\php\php5.3.13\php.exe" -q "C:\wamp\www\test\scripts\apiTest.php %1" > API_Log%dtStamp%.txt

然后使用argv变量访问该数据。

echo $argv[1];

因此运行C:\wamp\www\test\scripts\apiTest.bat 1234567将回显1234567

另外,如果你需要它,命令在$argv[0] ,我有时在输出我的脚本的语法时使用它。 例如:

echo "Syntax: {$argv[0]} [username]";

Instead of sending it like a GET request you should use something like:

start /b "C:\wamp\bin\php\php5.3.13\php.exe" -q "C:\wamp\www\test\scripts\apiTest.php %1" > API_Log%dtStamp%.txt

and then access that data with the argv variable.

echo $argv[1];

So running C:\wamp\www\test\scripts\apiTest.bat 1234567 will echo 1234567

Also just in case you need it, the command run in $argv[0], I sometimes use this when outputting the syntax of my script. For example:

echo "Syntax: {$argv[0]} [username]";

更多推荐

本文发布于:2023-08-02 23:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1382428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   批处理文件   url   php   wamp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!