The easiest way to count pages is view your document on-line with a PostScript previewer. Some previewers like Ghostview and GSPreview count the pages for you. (See the comp.sources.postscript FAQ, which has a section ``PostScript Interpreters and Utilities''.)
If your document is generated by a program compliant with the Document Structuring Conventions, you should be able to just count the number of ``%%Page:'' comments imbedded in the document. With UNIX you can type
grep -c %%Page: document.psto do this counting. (See Section 9, ``Encapsulated PostScript''.)
You could use the program pspages posted to comp.sources.postscript, volume 2, issue 5, by Kevin Grover.
The only completely reliable way to count pages is to ask the printer after the job is printed. PostScript printers maintain a page counter that can be queried before and and after the job is printed, and the page count is a simple subtraction. This tends to require rather sophisticated spooling systems and a communications channel that is bidirectional. However, some printers allow you to submit jobs on one port, and issue queries on another.
Send this PostScript through a bidirectional I/O port and you'll get back the page count, nominally the total number of pages printed since manufacture:
statusdict begin pagecount == end flush
Experts using a level 2 printer can use the SerialOff.PS and SerialEHandlder.ps programs to communicate bidirectionally to the printer.