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

But how to know whether user terminates system("$cmd|more") with q or not in the first place?

There is no (simple*) way to do this. The 'q' character is only seen by the more process and it doesn't share any information about how it is terminated.

The simplest way to achieve something similar would be to use a piped-open to run the command (without using more) and Term::ReadKey to simulate the more commands.

(*) Theoretically it would be possible to have the parent process capture all input from the console and inject it into the child processes input stream, but it would be a substantial amount of very non-trivial coding. Using a piped-open and simulating more is much easier.


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.
  • Comment on Re: How to know whether user terminates system("$cmd|more") with q or not?