in reply to Re: How to monitor a child process from a perl script
in thread How to monitor a child process from a perl script

Yes, you are right about the pmemd. However it has multiple output files. The whole command looks something like this:

pmemd -i mdin -c inpcrd -p prmtop -r restrt -o mdout -x mdcrd

restrt mdout and mdcrd are outputs while mdout is the one I am going to moniter changes.
So how do you specify that very file in open?
  • Comment on Re^2: How to monitor a child process from a perl script

Replies are listed 'Best First'.
Re^3: How to monitor a child process from a perl script
by BrowserUk (Patriarch) on Aug 13, 2009 at 05:35 UTC
    you are right about the pmemd. However it has multiple output files.

    But you only wish to monitor one of them, right?

    If so, then do as I suggested above, but with the extra options required. And if you need to retain the file (mdout) that would have been produced had you not redirected it, just write it yourself as you monitor the output.

    On Win*, it might look something like:

    my $pid = open KID, '-|', 'pmemd -i mdin -c inpcrd -p prmtop -r restrt -o con -x mdcrd' or die $!; open OUT, '>', 'mdout' or die $!; while( <KID> ) { kill 'INT', $pid if m[some data]; print OUT; }

    Again, I don't know the correct syntax for *nix. Maybe something like this would work?:

    my $pid = open KID, '-|', qq[pmemd -i mdin -c inpcrd -p prmtop -r restrt -o /dev/tty -x mdcr +d] or die $!; open OUT, '>', 'mdout' or die $!; while( <KID> ) { kill 'INT', $pid if m[some data]; print OUT; }

    Note the use of the list form of open to avoid a shell process.


    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.
      I don't quite get your code, could you explain little bit to me?

      1. Is KID a Filehandle, which file does it point to?
      2. '-|' allows reading from the output file of pmemd command?
      3. Since I'm using Linux, so what is /dev/tty

        1. Yes. A file handle to a pipe connected to the stdout of the child (KID) process started by the forked open.

          Since you know enough to write this, I obviously don't need to explain that further. Everything you need to know is in the documentation I've already pointed at.

        2. No. It allows reading from the stdout out of the child process.

          All you need to do is arrange for pmemd to write the file you are interested in to stdout.

          On Win*, You can con [sic] a program into writing to the console instead of the filesystem but asking it to write to the psuedo-filename con.

          You supply that string as a filename, the program opens the file in the normal way and writes to it, completely unaware that its output is going to the console. Where it can be read by a monitoring process via pipe.

        3. As I explained, I do not know for certain that /dev/tty is the correct psuedo-filehandle equivalent of con.

          It could even be that there is no way to do this on *nix. I'd be surprised, but it is possible,

          You'll need to look up the documentation on your system to find that answer. It is beyond my knowledge.


        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.