2

I want to execute a php file using php.exe installed with Xampp.

Xampp install dir is C:\xampp\ So the path of php.exe is C:\xampp\php\php.exe

I changed the DOCUMENT_ROOT in apache config file, so, my root is the drive O:\

The php file that I want to execute simply make another file in the same folder. Just to see if the execution work.

[make.php] Path => O:/make.php

<?php
    $f=fopen(date("d_m_Y_H_i_s").".txt","a");
    fclose($f);
?>

When I open my browser and start http://localhost/make.php the txt file is generated correctly.

So all works! Now I want to do the same thing not using the browser but php.exe

Right click on php.exe, run as administrator, ( UAC disabled and no account password ) type "O:\make.php" press enter but nothing happens...

Tried also with "O:/make.php", "make.php", "php make.php", "php O:/make.php", "php O:\make.php".

Someone have any ideas?

fmineo
  • 804
  • 3
  • 11
  • 28
  • Type `php.exe O:\make.php` in the command line, or create a shortcut to PHP.exe and modify it to add the file at the end. – apokryfos Feb 09 '17 at 12:35
  • Not work, I type this command on php.exe, not command prompt or powershell. Already tried with cmd and powershell with "C:/xampp/php/php.exe -f O:/make.php" or with back-slashes. But still nothing... – fmineo Feb 09 '17 at 12:38
  • Are you sure it's not working? How about changing the script to do `$f = fopen(__DIR__.DIRECTORY_SEPARATOR.date("d_m_Y_H_i_s").".txt","a");` instead so you'd be sure where the file should be created? – apokryfos Feb 09 '17 at 12:40
  • If I execute this on browser it works, but not using the php.exe T_T – fmineo Feb 09 '17 at 12:45
  • I found the solution on this post. http://stackoverflow.com/questions/15597067/how-to-run-php-from-windows-command-line – fmineo Feb 09 '17 at 12:57

4 Answers4

0

From Windows You must use the Task Scheduler (from the Control Panel)

Create a new task which will launch the PHP binary, with the cron.php script path as an argument every 5 minutes

Examples :

"c:/pathtophp.exe c:/web_folder/glpi/front/cron.php " With Wampp

c:/wampphpphp.exe c:/wamp/www/glpi/front/cron.php With Xampp

Run : C:/(…)xampp/php/php.exe -f cron.php

Start in : C:/(…)xampp/htdocs/glpi/front

Isaac Aguilar

0

Because you use XAMPP you need to specify the path like so :

C:\xampp\php\php.exe O:/make.php

edit: You can also add a variable enter image description here Windows 10 and Windows 8

In Search, search for and then select: System (Control Panel)

Click the Advanced system settings link.

Click Environment Variables.

In the section System Variables find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.

In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.

Now in any BATCH file (.bat) just use %PHP%. enter image description here

So if you change your mind and use another package or use directly PHP, you will just need to change the Path of the variable.

Patfreeze
  • 680
  • 6
  • 16
-1

On powershell or commad prompt php -r "echo PHP_VERSION;" gives the version

or exe any other php command

VPDD
  • 131
  • 4
  • 7
-2

You can write a batch-file with following content and put it in the same directory as your make.php file.

php make.php

With that batch you can execute your php-file.