Mailing List Archive

pipe-open on Windows tells porkies about failures
I got an interesting CPAN-testers failure recently:
https://www.cpantesters.org/cpan/report/adf8485b-6c60-1014-b56d-e7e4bfdedd6e
https://www.cpantesters.org/cpan/report/962cc9a4-6bf5-1014-ac30-9c81686fcd47

for this code:
https://metacpan.org/release/DCANTRELL/CPAN-FindDependencies-3.07/source/t/multi.t

As you can see, the test attempts to divine whether `bzip2` is installed
by using a pipe-open, and if that fails it will skip the tests. This
works just fine on Unix-a-likes, skipping the tests as appropriate, and
all the code works on Windows if `bzip2` is installed:
https://ci.appveyor.com/project/DrHyde/perl-modules-cpan-finddependencies/builds/39877167/job/e3fiy4xsu1xcd1o6

But on Windows if `bzip2` is *not* installed then the 2-arg form of
open() returns true even when the open() fails. I am led to believe that
this is because in this case perl constructs a `cmd` wrapper around
`bzip2`, and `cmd` can be executed. perl should also check whether `cmd`
reports an error.

No doubt if I used the list form of open() everything would work, as
there's no shell interpretation required then, but I can't because that
doesn't support pipe-open on Windows perl < 5.22.

Is this a bug, or is it documented somewhere and I've just not found it?
(In which case is it a documentation bug? `perldoc -f open` should, I
think, contain at least a hint :-)

--
David Cantrell | Bourgeois reactionary pig

Support terrierism! Adopt a dog today!
Re: pipe-open on Windows tells porkies about failures [ In reply to ]
On Thu, 08 Jul 2021 11:50:33 +0200, David Cantrell <david@cantrell.org.uk> wrote:

> I got an interesting CPAN-testers failure recently:
> https://www.cpantesters.org/cpan/report/adf8485b-6c60-1014-b56d-e7e4bfdedd6e
> https://www.cpantesters.org/cpan/report/962cc9a4-6bf5-1014-ac30-9c81686fcd47
>
> for this code:
> https://metacpan.org/release/DCANTRELL/CPAN-FindDependencies-3.07/source/t/multi.t
>
> As you can see, the test attempts to divine whether `bzip2` is installed
> by using a pipe-open, and if that fails it will skip the tests. This
> works just fine on Unix-a-likes, skipping the tests as appropriate, and
> all the code works on Windows if `bzip2` is installed:
> https://ci.appveyor.com/project/DrHyde/perl-modules-cpan-finddependencies/builds/39877167/job/e3fiy4xsu1xcd1o6
>
> But on Windows if `bzip2` is *not* installed then the 2-arg form of
> open() returns true even when the open() fails. I am led to believe that
> this is because in this case perl constructs a `cmd` wrapper around
> `bzip2`, and `cmd` can be executed. perl should also check whether `cmd`
> reports an error.
>
> No doubt if I used the list form of open() everything would work, as
> there's no shell interpretation required then, but I can't because that
> doesn't support pipe-open on Windows perl < 5.22.
>
> Is this a bug, or is it documented somewhere and I've just not found it?
> (In which case is it a documentation bug? `perldoc -f open` should, I
> think, contain at least a hint :-)

To add on to our conversation from last night:

I ran it through procmon and perl first tries to find bzip3 on its own, and THEN starts cmd.exe to see if THAT can find it, and since starting cmd.exe worked, you have a handle. Screenshot and text log attached.

--
With regards,
Christian Walde
Re: pipe-open on Windows tells porkies about failures [ In reply to ]
On Thu, Jul 8, 2021 at 6:08 AM David Cantrell <david@cantrell.org.uk> wrote:

> I got an interesting CPAN-testers failure recently:
>
> https://www.cpantesters.org/cpan/report/adf8485b-6c60-1014-b56d-e7e4bfdedd6e
>
> https://www.cpantesters.org/cpan/report/962cc9a4-6bf5-1014-ac30-9c81686fcd47
>
> for this code:
>
> https://metacpan.org/release/DCANTRELL/CPAN-FindDependencies-3.07/source/t/multi.t
>
> As you can see, the test attempts to divine whether `bzip2` is installed
> by using a pipe-open, and if that fails it will skip the tests. This
> works just fine on Unix-a-likes, skipping the tests as appropriate, and
> all the code works on Windows if `bzip2` is installed:
>
> https://ci.appveyor.com/project/DrHyde/perl-modules-cpan-finddependencies/builds/39877167/job/e3fiy4xsu1xcd1o6
>
> But on Windows if `bzip2` is *not* installed then the 2-arg form of
> open() returns true even when the open() fails. I am led to believe that
> this is because in this case perl constructs a `cmd` wrapper around
> `bzip2`, and `cmd` can be executed. perl should also check whether `cmd`
> reports an error.
>
> No doubt if I used the list form of open() everything would work, as
> there's no shell interpretation required then, but I can't because that
> doesn't support pipe-open on Windows perl < 5.22.
>
> Is this a bug, or is it documented somewhere and I've just not found it?
> (In which case is it a documentation bug? `perldoc -f open` should, I
> think, contain at least a hint :-)
>

I can't speak to whether this is a bug, but my recommendation would be (if
open returns true) to close $bzipfh afterward and then check $? for
nonzero, assuming you can guarantee that the command would succeed in
normal operation.

-Dan