Feature Proposal: Add IPC::Run to avoid re-inventing the wheel

Motivation

File::Which can be used to find the location of grep on the path, improving guessing of grep locations on OSX and FreeBSD which use a different location than linux.

IPC::Run does a very good job of capturing stderr, and would improve the configure Email test function, to capture the output from sendmail. We've had several users with email issues that the current debug facility didn't capture. IPC::Run might also be good to use in Sandbox to simplify the Foswiki code.

Description and Documentation

We can code these functions into Foswiki, but it makes better sense to use the CPAN modules.

Examples

Impact

%WHATDOESITAFFECT%
edit

Implementation

-- Contributors: GeorgeClark - 30 Jul 2012

Discussion

I've slotted this for 1.1.6, as these are more bugfix / robustness fixes than operational enhancements. Make it a bit easier for new installations to get Foswiki working. The only "feature" is adding to the list of distributed CPAN modules.

-- GeorgeClark - 30 Jul 2012

does IPC::Run replace much of what Sandbox does?

(I would have thought you could use Sandbox in 1.1.6 and then we can move over in 1.2.0

-- SvenDowideit - 31 Jul 2012

I don't think Sandbox will support sendmail, since we have to pipe in the composed multiline email into sendmail.

Anyway, after significant objections on IRC by SvenDowideit to adding any modules to a patch release, deferring this feature and both both bugs to 1.2.

Sven also argues that Sandbox should be refactored to use IPC::Run if that module is added. That's a bit too much boiling the ocean for me.

-- GeorgeClark - 01 Aug 2012

While we're adding sensible CPAN modules to replace old handcoded bugs, what about

-- SvenDowideit - 01 Aug 2012 Flipping to AcceptedProposal. Removed the File::Which part of the proposal. For now I'm not sure that it's needed.

-- GeorgeClark - 09 Oct 2012

Testing code that uses multiple external calls like DirectedGraphPlugin has shown that IPC::Run has some issues. On Windows, it was unable to reliably capture stdout when called for a sequence of programs.

CPAN:IPC::Run3 however works well on both Linux and Windows. It claims to have better portability and is lighter weight.

-- GeorgeClark - 19 Oct 2012

Maybe not. Seems to break the Eavesdrop code that UnitTestContrib uses to examine results sent to STDERR.

-- GeorgeClark - 19 Oct 2012

http://perldoc.perl.org/IPC/Cmd.html and http://perldoc.perl.org/IPC/Open3.html where what p5p mentioned - both are perl core, but um, IPC::Cmd is 5.10.0, which brings me back to - do we need 5.8.8 (jan 2006) or can we go 5.10 (dec 2007) - :/

-- SvenDowideit - 19 Oct 2012

I don't want to start the perl version battle here. It's covered in UseUTF8PerlRequirements.

So CPAN:IPC::Cmd (perl 5.009005) is a wrapper that uses:

What I think I'm running into is conflicting uses of redirect, capture, tie, etc. What started me down this path was the "configure test email" command, which was unable to capture the debug output from the external sendmail, but worked fine with Net::SMTP.

The email test uses a local *STDERR; open STDERR '>' $capture;. It successfully captures the print STDERR statements within Foswiki::Net, including those issued in Net::SMTP but does not capture any output from the open( $MAIL, '|-',... used to run sendmail. Using IPC::Run to capture the output, and then issuing a "print STDERR $captured" works.

Moving on to Sandbox::sysCommand(), it implements it's own attempt at portable capture. The code has been around a long time and works, but is complex, and would probably be better replaced by a CPAN module. I've experimented with the following:

$ Use IPC::Run: Worked fine on Linux. With Windows / Strawberry perl, it appeared to work until DirectedGraphPlugin was tested. For anti-aliased graphs, it runs in sequence: dot, identify and convert. IPC::Run seems to lose it's capture of STDOUT for the 2nd and 3rd commands. IPC::Run3 however worked. $ IPC::Run3: Seemed to work for Sandbox on Windows and Linux, however the configure test of sendmail failed to capture. The Run3 captured the output into a buffer, but the print STDERR of that buffer to pass the results to configure was lost.
  • Then I ran the Unit Tests. Unit::Eavesdrop attempts to tie STDERR and STDOUT to a common file. It was crashing with undefined file handles.

I'll give this all another try with IPC::Cmd but I'm wondering if there are too many captures going on especially with the unit tests.

-- GeorgeClark - 19 Oct 2012

Changing to a rejected proposal. Issues were fixed using other approaches, and no need to add more CPAN dependencies.

-- GeorgeClark - 09 Feb 2015
 
Topic revision: r13 - 19 Nov 2015, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy