in reply to How to know whether user terminates system("$cmd|more") with q or not?

Simply check the return value from system().

$ perl -e 'print system("some thing|more")."\n"'
prints 0 on this 'ere system if I quit 'more' by hitting q, 2 if I quit by hitting control-C, 35072 if I kill-9 the 'more' process, and 36608 if I kill -15. The exact values returned may differ slightly from one implementation of 'more' to another, but you're probably safe if you assume that 0 means the user hit q and non-zero means that 'more' terminated for some other reason - just don't try to portably determine what that other reason was!
  • Comment on Re: How to know whether user terminates system("$cmd|more") with q or not?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to know whether user terminates system("$cmd|more") with q or not?
by BrowserUk (Patriarch) on Sep 14, 2011 at 09:40 UTC
    0 means the user hit q and non-zero means that 'more' terminated for some other reason

    What value do you get if the user allows more to terminate on eof?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.