1

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?

2
  • Exactly how you've written. Is there a problem with that? Commented Sep 4, 2010 at 17:06
  • No, how do you RECIEVE the argument with the batch file Commented Sep 4, 2010 at 17:10

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

In the program I've used %* to access them all together.
2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.