views:

43

answers:

2

Using PHP's system function, how can you pass arguments to a batch file?

It would probably look something like this

system("batch.bat argument", $output);

I found out how to do it with a C++ executable here

I'm guessing it should be relatively simple...

What the real question is is how to receive the argument with a batch file?

+4  A: 

You are right, there is no difference. Here is a small demo:

First a batch file to just output its arguments:

C:\Documents and Settings\SO>type a.bat
@echo off
echo %*

A php program that uses system to invoke the batch file passing a and b as args:

C:\Documents and Settings\SO>type a.php
<?php
    system("a.bat a b",$out);
?>

On running the php, the call to system invokes the bat file with a and b as arguments, the batch file runs and echoes a and b

C:\Documents and Settings\SO>php a.php
a b
codaddict
So how do you get arg[1] arg[2] etc...
Mark
Each argument passed to BAT (or CMD) file is accessed with `%1`,` %2`, ...
codaddict
In the program I've used `%*` to access them all together.
codaddict
+2  A: 

Arguments in batch file are accessible as %1 %2 etc...

http://www.hccp.org/bat-cmd-line-args.html

http://www.rgagnon.com/gp/gp-0009.html

Mchl