Solved

How to run a PHP file (with arguments) from Win Batch File (with arguments)  ??

Posted on 2013-06-03
4
852 Views
Last Modified: 2013-06-03
I'm trying to run a batch file with an argument, which in turn passes that argument to a php file and runs.... I've tried a few different things but cant seem to get it working. Heres what I have:

process.bat (passed with a full path to a file (%1))

"C:\Program Files (x86)\PHP\php.exe" C:\inetpub\wwwroot\Label.php?File=%1
PAUSE

Open in new window


The above fails to run the PHP script with the following error:#

Could not open input file: C:\inetpub\wwwroot\Label.php?File=%1?File=C:\WatchFolder\label1.txt

Does anyone know how I can correctly pass the %1 batch file argument through to the PHP script?

Thanks
0
Comment
Question by:Bergstr
  • 2
4 Comments
 
LVL 10

Expert Comment

by:rjanowsky
Comment Utility
Did you check this document: PHP Command Line on Microsoft Windows? There are some concrete infos to get it running.
0
 

Author Comment

by:Bergstr
Comment Utility
I don't think the problem is running a PHP file from a batch file (I've already got that working) - the bit I cant work out is how to get the variable from the batch file into the PHP, and then utilise the variable within the PHP,

Since I first posted, I've noticed the following DOES work, but I cant figure out how you get PHP to read the argument data.

"C:\Program Files (x86)\PHP\php.exe" C:\inetpub\wwwroot\Label.php %1

Open in new window

^ works

"C:\Program Files (x86)\PHP\php.exe" C:\inetpub\wwwroot\Label.php?File=%1

Open in new window

^ Doesn't work

I've tried using $argv but cant echo that into a file? i'm going to try running a loop on the $argv and see if that works, will report back with how I get on!
0
 
LVL 7

Accepted Solution

by:
msifox earned 500 total points
Comment Utility
$argv is an array.
$argv[1] is the first argument that you specified.
0
 

Author Comment

by:Bergstr
Comment Utility
that worked! thank you!
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now