http://www.perlmonks.org?node_id=850542


in reply to Wrap around an interactive python script

You can do this through open pipe, but you might run into some buffering problems.

open(LOG,">>/path/to/log"); open(SYS,"/path/to/python/script.py |"); while (<SYS>) { print $_; print LOG $_; } close(SYS); close(LOG);

This way you can print to screen and to your log file

Replies are listed 'Best First'.
Re^2: Wrap around an interactive python script
by rastoboy (Monk) on Jul 21, 2010 at 04:08 UTC
    I've recently started using IPC::Open3::open3 for InterProcess Communication type purposes and haven't looked back. Makes it easy to interact with another application by just reading and writing to filehandles, very slick and more intuitive (at least for me, anyway).

    But I'm still quite the amateur and may be missing some subtleties (or outright facts).

      While open3 does a lot (incl propagating exec errors to the parent), it's still a low level module. It's doesn't help you read from the child's STDOUT and its STDERR without combining them, a situation prone to deadlocks. IPC::Run3 and IPC::Run are higher-level solutions.