Programmer of Windows Tasks

Asked

Viewed 245 times

1

I have a question regarding the Windows task programmer

I got everything going normal. Opens the Browser and executes the php code.

But then there is the possibility that in the end close that same page alone?

  • 1

    How about a window.close(); in JS itself?

  • At the end of php?

  • After PHP, open <html> and put <body onload="window.close();">. But that would be a scam, better do as @lost replied.

3 answers

8


If you need to run a php script automatically, call it from the line instead of invoking IE with the page/script you want, so you don’t worry about closing the browser when processing the window cmd will be closed.

In your bat call php this way:

php -f "C:\caminho_completo\script_automatico.php"

For the command to be recognized in the DOS terminal it is necessary to add the php executable path to the variable PATH windows.

This can be done through the shortcut win-key+break/pause or right click on (my)computer > properties > advanced system settings, advanced guide > environment variables. Create a new call PHP_HOME its value is the folder where is the . exe of php. Done this add the PHP_HOME at the PATH at the end place: ;%PHP_HOME%;.

To test open a new cmd and type php -v if all is right it should display the php version.

  • but opening like this works in the email.php file? And I can run it every day at 12h?

  • @Chrisadler works correctly, create a . bat file, with the above content and schedule it. Your script doesn’t need any interaction/response from the right user?

  • I put: php -f "C: wamp www folder emailteste.php" appears the cmd window and closes and nothing else happens.

  • @Chrisadler, then there was an error, add a line with the following command pause so you can see what was written.

  • Thanks. error: 'php' is not recognized as internal command...

  • @Can Chrisadler tell if there is an environment variable as php(executable) path? it should be added to PATH windows. You can see this by pressing the key windows + break > configurações avandaçadas do sistema flap avançado.

  • I found in the system variables the PATH and then I have to follow the path that appears there and add? or edit ? I never touched this part

  • @Chrisadler the ideal is to create two of them the PHP_BIN her value will be something like c:\xampp\php\php.exe and the PHP_HOME with the value: c:\xampp\php. After creating the two you need to change the variable PATH in the fine setting ;%PHP_HOME%;%PHP_BIN%; To check if it worked open a new cmd and type php -v.

  • I tried several ways yesterday and today and it still doesn’t work. I don’t use Xampp but I use Wamp but it should be the same?

  • @Chrisadler, how did you leave the PHP_HOME and put the end of the PATH

  • C: wamp bin php php5.4.16 php.exe . path: C: Program (...);%PHP_HOME%;%PHP_BIN%;

  • @Chrisadler is to be just that. PHP_HOME and PHP_BIN were created in system variables or user variables?

  • both in system variables

  • 1

    I’ve got it working. Thank you very much

  • @Chrisadler, what was wrong? good that solved.

  • 1

    I just put in path C: wamp bin php php5.4.16

Show 12 more comments

1

You can make an event by calling a batch, in this batch you control the behavior:

taskkill /f /im chrome.exe >nul 2>nul

start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" http://localhost/

taskkill /f /im chrome.exe >nul 2>nul

0

When you want to close the window you can do the following:

echo "<script>window.close();</script>";

But depending on its application, the reply @lost would be better calling PHP in your bat this way:

php -f "C:\caminho_completo\script_automatico.php"

To make calls to the system PHP has the function system(), read the documentation :

string system (string $command [,int &$return_var])
  • It will only be to send email. But as I did I had to manually close the page

Browser other questions tagged

You are not signed in. Login or sign up in order to post.