Answer the question
In order to leave comments, you need to log in
How not to close the console (and not to display too much) when calling the PHP-CLI console script?
I want to make a console php script so that when you double-click on a file, the console opens (the Terminal program in Mac OS X), the script displays the result of the work, and the console does not close. But at the same time, so that nothing superfluous and distracting is displayed.
For example, I create a file "Hello"
or "Hello.command"
with this content:
#! /usr/bin/env php
<?php
echo "\n\nПривет мир!\n\n";
Last login: Mon Aug 1 01:13:40 on ttys004
MyMac:~ user$ /Users/user/folder/bin/test ; exit;
Привет мир!
logout
[Процесс завершен]
Answer the question
In order to leave comments, you need to log in
Found a solution. Of course, this is a hack, but it almost looks like it should:
#! /usr/bin/env php
<?php
system('clear');
echo "\n\nПривет мир!\n\n";
echo "\033[37m" , "Нажмите Esc для выхода..."; // светло-серая подсказка
system("stty -icanon"); // отключение буферизации символов в терминале
while( ord( fread(STDIN, 1)) != 27 ) {} // считываем нажатые символы, до нажатия Esc
exit;
In general, this is not quite the right approach. You need to solve this problem at the terminal level. It's just that what you do on click is initially such a procedure that the terminal window will be open only until the process has completed.
At the PHP level, you can, of course, resort to a hack and, for example, wait for input . But this is conceptually wrong.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question