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.
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.
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
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.
Related
my question is how to get output of terminal in php? I mean i want to create a website where users could view what's happening in the terminal. I want to "capture the terminal" and then echo it in PHP. I don't know how to really explain this so if you didn't quite understand me, please ask me what you didn't understand. Thanks.
The solution you are working for is "terminal screencasting", that is the term to google ;-)
Some solutions :
script and scriptreplay linux commands
type script /var/www/log/history_log.txt for starting logging what you type in the shell
you then type anything command ; to stop script, type exit and press [Enter].
And the log will be available in the file history_log.txt
More informations here https://www.tecmint.com/record-and-replay-linux-terminal-session-commands-using-script/
and here https://www.linux.com/learn/using-screen-remote-interaction
ShowTerm :
There is also the solution ShowTerm, more informations here : https://www.tecmint.com/showterm-io-a-terminalshell-recording-upload-and-share-tool-for-linux/
tty2gif :
more informations here, https://github.com/z24/tty2gif
asciinema :
web based solution (with linux tool to install) : https://asciinema.org/
So PHPstorm is running the php code fine in its console when I click run, that's great but I want to see it in the browser.
So I created a new PHP web application inside PHPstorm, set up the server to "localhost:8000".
Now when I click RUN it opens the browser but I get an error message: "Oops! Google Chrome could not connect to localhost:8000"
What am I doing wrong??
Thanks!
You have to configure a run configuration for your project first.
Go to Run -> Edit Configurations, click on "PHP Built-in Web Server" and then press "+". You should see something like this:
After saving the settings you can run the web server via Run -> Run '<project-name>'. It should now serve up the pages to your browser.
I was trying some things with osascript when I had this problem.
Here is my test :
/usr/bin/osascript <<-EOF
tell application "System Events"
activate
display dialog "Hello world"
end tell
EOF
Here is my PHP file.
<?php
$output = shell_exec("./test");
echo "<pre>$output</pre>";
?>
Do you have any ideas why this does not work? (It's not really important but I was just curious about it)
I suspect the osascript executable requires environment variables to be set up to work correctly, which is why this works fine from the console. See this answer to show you how to set these up from PHP.
In my case it was the HOME variable, but it could be something else. Keep adding them until it works!
I'm making a Minecraft control panel, but are sort of confused on how to send a command to each screen. I understand how to execute a command to a screen, but I don't understand to read the output.
Ex. I have screen A and screen B. I want to execute something in screen A, and get the output, and then exit the screen.
Here's an easier solution:
Use Websend bukkit plugin (Download&info) in both servers. PHP can simply execute commands and receive outputs when plugin is installed and php classes setted up, also this can be more complex than bash screen, and much easier to setup and use.
Here's an example use of this:
<?php
include_once 'Websend.php';
//Replace with bukkit server IP. To use a different port, change the constructor to new Websend(ip, port)
$ws = new Websend($ServerIP, $ServerPort);
//Replace with password specified in Websend config file
$ws->connect("password");
$ws->doCommandAsConsole("give ".$PlayerName." 64 1");
$ws->disconnect();
?>
In this example the script item to a variable-definied player.
You can execute a custom variable command with replacing $ws->doCommandAsConsole("give ".$PlayerName." 64 1");' to$ws->doCommandAsConsole("$_REQUEST['customCMD']"); where customCMD is a field in a GET or POST form.`
Don't actually need a plugin, but keep in mind using shell_exec could open a massive world of pain for you when it comes to security.
However, I was having a similar issue with implementing a control panel in drupal, I managed to run commands to a screen using the following code.
shell_exec("screen -S ScreenName -X stuff \"echo hello world\"'\n'");
You're welcome.
I was wondering how I could execute a command through PHP into a screen running on my virtual private server.
i.e.
if(submit){
do "say This is a minecraft server." in screen.
}
Thanks in advance,
If you are running the script under screen, then just echo or print the data you want to display.
Otherwise you can:
make a system call to write or wall
write to a file that you are tail -fing in the screen (or some other system by which the screen polls something for new messages)
run a service in the screen that you can connect to over the network
Still unclear on exactly what you mean, but if this is what you're looking for, you can execute linux commands by using the backtick operator, such as
echo `ls`;
to print the contents of the directory where the script is located. So if you wanted to print commands to your server, you could do it that way.