views:

1510

answers:

3

Is it possible to send messages from a PHP script to the console in Eclipse? Has anyone attempted this already? I'm not very familiar with how the console works, so I'm not sure if there is a standardized method for communicating with it.

A: 

All output from an Eclipse external tool launch goes to the console by default, so if you execute a PHP script using an external tool launcher any output from the script will go to the console.

For example:

<?php

echo "Hello World\n";

?>

Will send "Hello World" to the console.

+4  A: 

If you look at...

Main Menu -> Run -> External Tools -> Open External Tools Dialog.

In there I have set up PHP Codesniffer with the following...

  • Name : Code Sniffer
  • Location : /usr/bin/phpcs
  • Working Directory : ${workspace_loc}
  • Arguments : --standard=${resource_loc}

That runs the codesniffer as an external tool and all the messages it returns appear in the console. Once you have set it up, click the down arrow and choose "Code Sniffer" and then anything the external program (in this case codesniffer) outputs will be in the Eclipse console.

If you set it up like this...

  • Name : PHP
  • Location : /usr/bin/phpcs
  • Working Directory : ${workspace_loc}
  • Arguments : ${workspace_loc}${resource_path}

It will just run php in CLI mode and if you run it with Wilco's code (above) you will get.

Hello World

In the terminal.

Hope that helps.

Uresu
A: 

Any echo or print you do should go to the console automatically. This has been very unreliable for a long time, however. Please vote to have this bug fixed at:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=282997

Sandor Vroemisse