php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #31516 Clear screen or ScreenSize
Submitted: 2005-01-12 14:26 UTC Modified: 2017-01-29 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: csaba at alum dot mit dot edu Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.0.3 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: csaba at alum dot mit dot edu
New email:
PHP Version: OS:

 

 [2005-01-12 14:26 UTC] csaba at alum dot mit dot edu
Description:
------------
From a command line php.exe invoked from a cmd prompt under Win XP Pro, I'd like to be able to blank the screen and/or determine the screen height.

Motivation:
I have a program that takes several hours to run and it shows several lines of progress statistics, which are periodically updated.  I'd like to keep this presentation professional.

I could simulate what I'm asking by interspersing 1000 "\n" whenever I'm printing an updated set of stats.  However, this puts the info at the bottom of the screen.  If I could programatically determine the height (since it might be changed/stretched/shrunk by the user) of the DOS (CMD) screen in lines then I could compensate for it (and if you give me that, I'd like to know the width, too, please).  

Alternately, if there was a simple way to blank the screen with the cursor starting off at the top left, that might be another way to go (sort of a PHP issued CLS).

Thanks for considering whether this is possible/reasonable,
Csaba Gabor from Vienna

Note:  This is distinct from http://bugs.php.net/bug.php?id=24109 because (1) as I understand it, ncurses does not apply here because it does not work for DOS/cmd prompts. (2) I want to reuse the current window.

Apropos:  Perhaps an alternate approach (Ie. feature request) is to ask PHP to return a handle to its parent process.  Perhaps it is possible to query that (using Windows APIs) for its properties.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-12 16:26 UTC] derick@php.net
Just send the appropriate escape sequence, afaik this should work:

echo chr(27), "[2H";

 [2005-01-12 16:29 UTC] derick@php.net
almost ;-)

<?php
echo chr(27), "[H", chr(27), "[2J";
?>

 [2005-01-12 19:20 UTC] csaba at alum dot mit dot edu
Thanks Derick, this is exactly the kind of thing that I was looking for.  Unfortunately, as I make it out, there is a problem (and I here document the steps):

For this to work ANSI.sys must be a driver for the command prompt, but this will only work under COMMAND.COM.  To do this, as described at
http://www.evergreen.edu/biophysics/technotes/program/ansi_esc.htm
and http://support.microsoft.com/default.aspx?scid=kb;en-us;Q101875
I first edit my \windows\system32\CONFIG.NT file by adding to the three existing lines:
dos=high, umb
device=%SystemRoot%\system32\himem.sys
files=4

the following two lines:
DEVICEhigh=%systemroot%\system32\ANSI.SYS
dosonly

and save it as CONFIGDS.NT

Now I create a new shortcut in windows and point it to \windows\system32\COMMAND.COM  In the advanced section under the Program tab, for Config filename I put:
%SystemRoot%\SYSTEM32\CONFIGDS.NT

For testing, I make a batch file with a one line entry:
echo {ESC}[2J
where that {ESC} is the escape character (hex 1B)
If I run the batch file, the screen is reset to my expectations.

UNFORTUNATELY, when I try to run PHP, I get the following message:
This program cannot be run in DOS mode.

Unless I've missed something in seems like PHP and the ANSI control codes are mutually exclusive on Win XP and Win 2K.

Csaba
 [2017-01-20 20:27 UTC] heiglandreas@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2017-01-20 20:27 UTC] heiglandreas@php.net
Is this still relevant?
 [2017-01-29 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC