Solved

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

Posted on 2013-06-03
887 Views
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


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
Question by:Bergstr
• 2

LVL 10

Expert Comment

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

Author Comment

ID: 39215810
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

^ works

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

^ 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

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

Author Comment

ID: 39216000
that worked! thank you!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …