Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I have a batch file called "program.bat"... and I'm on the command line... I can just type program to get the program to run.

If I'm on the command line, how do I get program.php to run automatically the same way instead of having to enter php program.php?

Say I have PHP installed to C:\programs\PHP and C:\Programs\Scripts attached to PATH. What needs to be done to be able to create C:\Programs\Scripts\hw.php with the content

<?php Echo "Hello World!"; ?>

and have it so that on the command line I type hw?

Windows XP Pro, SP2
PHP 5.3.8

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You can create a file association for .php. See the documentation for assoc and ftype That should get you to where typing program.php causes php.exe to be invoked and passed program.php.

To eliminate the need to type the '.php' suffix I suspect you need to tell Windows that .php is an executable extension. See On Windows, what filename extensions denote an executable? re the PATHEXT environment variable. I have not tried this myself.

share|improve this answer
    
php.net/manual/en/install.windows.commandline.php Assoc and FType got me searching for the right thing. –  WernerCD Oct 17 '11 at 20:35

How about creating a hw.bat, and put php hw.php in it? Then you can just run "hw".

share|improve this answer
    
I'm trying to be lazy... last thing I want to have to do is setup two scripts for each task I want to do. Works? Yeah... but definitely not optimal. –  WernerCD Oct 17 '11 at 20:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.