tags:

views:

270

answers:

3

I have lots of experience of writing php scripts that are run in the context of a webserver and almost no experience of writing php scripts for CLI or GUI output.

I have used the command line for linux but do not have much experience with DOS.

Lets say I have php script that is:

<?php
echo('Hello world');

for ($idx = 0 ; $idx < 100 ; $idx++ )
    {
    echo 'I am line '. $idx .  PHP_EOL;
    }

Then, I run it in my DOS Command prompt:

 # php helloworld.php

Now this will spurt out the output quickly and i have to scroll the DOS command window up to see the output.

I want to see the output one 'screen full' at a time.

How do you do that from the perspective of a DOS user?

Furthermore, although this is not my main main question, I would be also interested in knowing how to make the php script 'wait for input' from the command prompt.

+5  A: 

php helloworld.php | more

More on more.

More on command line redirection.

jeffamaphone
I had no idea that worked in MS DOS as well.
Mark Tomlin
just to add: Hit RETURN to see the remaining lines and Pressing CTRL+C allows you to exit the command early.
JW
+2  A: 

You can redirect the output to a text-file and refer the text-file after the command execution is completed.

C:/>dir > output.txt
this. __curious_geek
nice. thanks for that
JW
A: 

In general, I'd count however many lines, then stop and wait for a user input. Perhaps with an "any key to continue" if there's a possibility of confusion.

You could also build in a time delay, but personally I hate programs that display a message for a fixed amount of time and then clear it. What if someone walks in the office and distracts me just as the message comes up? I prefer requiring a positive response.

Jay
JW
Personally I think command-line programming is of pretty limited use. I'd go to GUI programming. Command-line is good for quick and dirty, and for tools that you want to pipe together like a lot of Linux things do. But it's not pretty enough for modern users.
Jay
Yes, I am heading toward GUI, but I think understanding how CLI programs work (or more specifically how apps interact with an operating system as opposed to a web server), seems to be a perquisite for learning GUI apps. I am pretty skilled at writing apps for request-driven-architecture but have limited knowledge about event-driven-architecture.
JW
Does PHP have a way to create a GUI? The only PHP I've done has been web pages. You might want to start learning Java or C#. Yes, I think you'll find that GUI programming is more difficult than web apps, or at least more tedious, because you have to deal with responding to every control on the page individually rather than letting the browser collect everything and hand it to you as a package. On the other hand, it's much more flexible.
Jay
Update: This blog post is the perfect example of the knowledge that has eluded me whilst developing for a web server. http://robmensching.com/blog/posts/2003/9/24/Setup-is
JW