Pass value from html to batch file

Hello -
I'm working with an existing html/php web page that has about 7 links that call almost identical batch files to perform a series of steps, such as renaming a file and moving it to another location.

I'd like to use just a single batch file by passing a parameter from the web page to the batch file, and based on this value, will determine the new name and location for the file.  The value of the parameters can be as simple as a, b, c, d, e, f, g; it's just a way for the batch file to know which link the user clicked on.

Currently I have a link such as:

I'd like to have:
href="file:\\dev_server\scripts\script.cmd /p='a'" (or however one would indicate a parameter)
href="file:\\dev_server\scripts\script.cmd /p='b'"

How would I do this with html and/or php?  

I started reviewing this post,, but in this case I don't want input from the user; instead the parameter will come from the particular link that the user clicks on.

I am very, very new to html and php and I'm learning, but not fast enough to complete this project on time. :-)

Thank you!
tancatOracle DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mark BullockQA EngineerCommented:
Do you want the batch file to execute on the user's client computer or on your server?
Dave BaldwinFixer of ProblemsCommented:
Does any of that even work at all?  I ask because if you are using Firefox or Chrome, they won't open those 'file://' links.
tancatOracle DeveloperAuthor Commented:
What I currently have works.  The desire is to have a single batch file instead of seven.

The batch files execute on the server, I believe.  I mean, they are stored on the server; when someone clicks on the link and a command box pops up, isn't that executing on the server but displaying on the client?  

The users used to click on a separate link for each step, but the batch files I'm using now just echo a comment to the user when each step is completed (along with a pause).  If the step doesn't complete successfully, an error message is displayed and the users will take a screen shot and send it to me.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Chris StanyonWebDevCommented:
Hey tancat,

Clicking on the link to a batch file will attempt to run it on the client, not the server (unless the client is the server!).

Your best bet here would be to create a PHP script to do what you need. PHP is more than capable of doing everything a batch file can do (and more).

To pass parameters to a PHP script via a link, you append what's called a querystring to the script name:

<a href="myScript.php?p=a">Click Me<a/>

In the line above you are passing a variable called p with a value of a. You can pass more than 1 by stringing them together with the & symbol:

<a href="myScript.php?someVariable=chris&anotherVariable=ee">Click Me<a/>

In the script, you would retrieve these variables from the $_GET array, so something simple like this:

$myName = $_GET['someVariable'];
$variable2 = $_GET['anotherVariable'];

echo $myName;
echo $variable2;

Open in new window

If you want to copy a file, then use the php copy() command. To move a file, use the rename() command.

There are a couple of gotchas to be aware of, such as checking that a value has actually been passed, and making sure that a user can't do something unintended by simply typing a different querystring into the browser, but these issues are generally straight-forward to prevent.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tancatOracle DeveloperAuthor Commented:
This is awesome!  Everything seems to be communicating nicely.  

I think the only thing I still need help with is to allow some acknowledgement from the user.  Currently the pause command in the batch file allows the user to see that the previous step was completed and they can hit any key to proceed to the next step; if the previous step was not successful it simply prints an error message so that I know where to troubleshoot.  Is there a way to do this, to get the user to "hit any key" (or something equivalent) in the myScript.php file?

I have some "button" code that I can modify, but I was hoping for something simpler.

I have not yet reviewed the links that you gave me; I'm sure a 'pause' equivalent is there, I just haven't figured out the terminology yet.  

Thank you so much for sharing with me.  I will definitely pay it forward when I become knowledgeable on this subject.  :-)
Chris StanyonWebDevCommented:
Excellent - seems like you're heading in the right direction.

There's no pause as such, as the PHP script will output to the browser once it's finished. If you want to break it into steps, then you could simply display another link. So the first link points to step1.php. You do what you need to in there, and if it's successful, you simply echo out another link to step2.php with a message saying Successful. If your step1.php failed, then simply echo out a message:

// example of step1.php
$somevar = $_GET['someVar'];

//do something with $somevar and set a boolean (true / false) variable - $success for example, depending on the outcome.

//Now check the $success variable 
if ($success) {
   echo "<h1>Success!</h1>";
   echo "<p><a href="step2.php?someVar=$somevar">Click here to proceed to Step 2</a></p>";
} else {
   echo "<h1>Fail!</h1>";
   echo "<p>Something went wrong.</p>";

Open in new window

As you build up your app, you can get more creative - like emailing you or logging the info if it fails, using a button instead of a link for the next step (a simply press of the Enter key would then proceed). PHP is pretty powerful, so you're only limited by your creativity (and current knowledge base!)
tancatOracle DeveloperAuthor Commented:
My apologies for being incommunicado.  It was strongly suggested that I needed to work on the documentation for this project, at which point I thought of a few other things or ways to solve some problems.  (I'm not sure that having the programmer write the requirements in the middle of development is the best course of action...)

As this question is solved, I will accept a solution.  (No promises that I won't be back, however!)

Dave - to answer your question, for this particular functionality my company only supports IE.  However, I do have it working in Firefox on my computer because I am using the Local Filesystem Links add-on.
tancatOracle DeveloperAuthor Commented:
I am very appreciative of the help and support that I have received from Chris Stanyon.  I have been able to solve a problem at work quickly, and look like I really know what I'm doing!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.