1

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

1

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.

1

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

  • 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
0

Type "assoc .php=PHP_program_file" at the command prompt. Also add .PHP; to the beginning of the environmental variable PATHEXT which is at System in the Control Panel, Advanced, Environmental Variables. Also add something like "C:\php;" to the beginning of the environmental variable PATH so you can also type "php hw.php" in addition to "hw.php" or "hw".

Then do the following in the registry editor:

Enter C:\php\php.exe "%1" %* in HKEY_CLASS_ROOT : PHP_program_file : shell : Execute PHP Program : command (Each colon means place a registry key inside the first registry key. Screenshot included.)

Registry editor screenshot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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