Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pl2bat cannot read from stdin #16367

Open
p5pRT opened this issue Jan 18, 2018 · 6 comments
Open

pl2bat cannot read from stdin #16367

p5pRT opened this issue Jan 18, 2018 · 6 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Jan 18, 2018

Migrated from rt.perl.org#132736 (status was 'open')

Searchable as RT132736$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 18, 2018

From martin@helios.de

Created by martin@helios.de

The "pl2bat" utility cannot read from standard input. Example​:

  C​:\> pl2bat < test.pl > test.bat
  pl2bat.bat​: Can't open -​: No such file or directory at C​:\Strawberry\perl\bin/pl2bat.bat line 101.

The reason seems to be that pl2bat uses open() with 3 arguments.

  open( FILE, '<', $file ) or die "$0​: Can't open $file​: $!";

which does not treat "-" as stdin. This used to work in earlier Perl releases, where the open() with 2 arguments is used.

Using pl2bat with stdin/stdout is an important feature for our build workflow.

Thank you for any help.
Regards, Martin

Perl Info

Flags:
    category=utilities
    severity=medium

Site configuration information for perl 5.26.1:

Configured by strawberry-perl at Sun Sep 24 05:36:07 2017.

Summary of my perl5 (revision 5 version 26 subversion 1) configuration:
   
  Platform:
    osname=MSWin32
    osvers=6.3
    archname=MSWin32-x64-multi-thread
    uname='Win32 strawberry-perl 5.26.1.1 #1 Sun Sep 24 05:32:33 2017 x64'
    config_args='undef'
    hint=recommended
    useposix=true
    d_sigaction=undef
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=undef
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='gcc'
    ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -D__USE_MINGW_ANSI_STDIO -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fwrapv -fno-strict-aliasing -mms-bitfields'
    optimize='-s -O2'
    cppflags='-DWIN32'
    ccversion=''
    gccversion='7.1.0'
    gccosandvers=''
    intsize=4
    longsize=4
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='long long'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='g++'
    ldflags ='-s -L"C:\STRAWB~1\perl\lib\CORE" -L"C:\STRAWB~1\c\lib"'
    libpth=C:\STRAWB~1\c\lib C:\STRAWB~1\c\x86_64-w64-mingw32\lib C:\STRAWB~1\c\lib\gcc\x86_64-w64-mingw32\7.1.0
    libs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    perllibs= -lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32
    libc=
    so=dll
    useshrplib=true
    libperl=libperl526.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_win32.xs
    dlext=xs.dll
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags='-mdll -s -L"C:\STRAWB~1\perl\lib\CORE" -L"C:\STRAWB~1\c\lib"'



@INC for perl 5.26.1:
    C:/Strawberry/perl/site/lib
    C:/Strawberry/perl/vendor/lib
    C:/Strawberry/perl/lib


Environment for perl 5.26.1:
    HOME (unset)
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;Y:\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\;C:\bin;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\TShell\TShell\;C:\Program Files\HELIOS.CD26\lib;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\Tcl\bin;C:\Program Files\HELIOS.CD26\bin;C:\Program Files\HELIOS.CD26\sbin;C:\ProgramData\Oracle\Java\javapath;c:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;Y:\bin;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\;C:\bin;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\TShell\TShell\;C:\Program
Files\HELIOS.CD26\lib;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin
    PERL_BADLANG (unset)
    SHELL=CMD.EXE

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 23, 2018

From @jkeenan

On Thu, 18 Jan 2018 16​:22​:43 GMT, martin@​helios.de wrote​:

This is a bug report for perl from martin@​helios.de,
generated with the help of perlbug 1.40 running under perl 5.26.1.

-----------------------------------------------------------------
[Please describe your issue here]

The "pl2bat" utility cannot read from standard input. Example​:

C​:\> pl2bat < test.pl > test.bat
pl2bat.bat​: Can't open -​: No such file or directory at
C​:\Strawberry\perl\bin/pl2bat.bat line 101.

The reason seems to be that pl2bat uses open() with 3 arguments.

open( FILE, '<', $file ) or die "$0​: Can't open $file​: $!";

which does not treat "-" as stdin. This used to work in earlier Perl
releases, where the open() with 2 arguments is used.

Using pl2bat with stdin/stdout is an important feature for our build
workflow.

Thank you for any help.
Regards, Martin

I believe you are correct.

The code in question was applied as part of an enormous patch which converted most of the source code and documentation to 3-arg 'open'. The size of the patch made it difficult to review closely -- and the fact that we have (AFAICT) no specific tests for pl2bat in the core distribution test suite meant that we had no way of realizing our error.

1. Poster​: Can you try out the patch attached? (I don't have Windows, so I cannot properly asses it.)

2. P5P​: Is there any way we could include a test of pl2bat in the test suite?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 23, 2018

From @jkeenan

132736-pl2bat-0001-Revert-to-2-argument-open-so-as-to-permit-reading-fr.patch
From 6a4e6837e3d6de1489718840157eeeaf0089d05e Mon Sep 17 00:00:00 2001
From: James E Keenan <jkeenan@cpan.org>
Date: Tue, 23 Jan 2018 11:37:31 -0500
Subject: [PATCH] Revert to 2-argument 'open' so as to permit reading from
 STDIN.

In commit 1ae6ead94905dfee43773cf3b18949c91b33f9d1, applied to blead on Dec 23
2016, almost all instances in the source code and documentation which used
two-argument 'open' were switched to 3-arg 'open'.  This had the unintended
side-effect of preventing 'pl2bat' being used with input from STDIN rather
than a file.  Thanks to Martin Reinders for reporting this problem.

For: RT # 132736
---
 win32/bin/pl2bat.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/win32/bin/pl2bat.pl b/win32/bin/pl2bat.pl
index 443f590..735fa0a 100644
--- a/win32/bin/pl2bat.pl
+++ b/win32/bin/pl2bat.pl
@@ -84,7 +84,7 @@ sub process {
     my $line;
     my $start= $Config{startperl};
     $start= "#!perl"   unless  $start =~ /^#!.*perl/;
-    open( FILE, '<', $file ) or die "$0: Can't open $file: $!";
+    open( FILE, $file ) or die "$0: Can't open $file: $!";
     @file = <FILE>;
     foreach $line ( @file ) {
 	$linenum++;
-- 
2.7.4

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 23, 2018

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 25, 2018

From martin@helios.de

On 23.01.18 17​:47, James E Keenan via RT wrote​:

I believe you are correct.

The code in question was applied as part of an enormous patch which converted most of the source code and documentation to 3-arg 'open'. The size of the patch made it difficult to review closely -- and the fact that we have (AFAICT) no specific tests for pl2bat in the core distribution test suite meant that we had no way of realizing our error.

1. Poster​: Can you try out the patch attached? (I don't have Windows, so I cannot properly asses it.)

2. P5P​: Is there any way we could include a test of pl2bat in the test suite?

Thank you very much.

That does not yet work because _two_ open calls (the input file for reading and the output file for writing) were affected by 1ae6ead. The attached patch reverts both open calls to the previous version, and fixes the issue in my test.

Regards, Martin

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Jan 25, 2018

From martin@helios.de

pl2bat.diff
diff --git a/win32/bin/pl2bat.pl b/win32/bin/pl2bat.pl
index 443f590..b30b16b 100644
--- a/win32/bin/pl2bat.pl
+++ b/win32/bin/pl2bat.pl
@@ -84,7 +84,7 @@ sub process {
     my $line;
     my $start= $Config{startperl};
     $start= "#!perl"   unless  $start =~ /^#!.*perl/;
-    open( FILE, '<', $file ) or die "$0: Can't open $file: $!";
+    open( FILE, $file ) or die "$0: Can't open $file: $!";
     @file = <FILE>;
     foreach $line ( @file ) {
 	$linenum++;
@@ -111,7 +111,7 @@ sub process {
     close( FILE );
     $file =~ s/$OPT{'s'}$//oi;
     $file .= '.bat' unless $file =~ /\.bat$/i or $file =~ /^-$/;
-    open( FILE, '>', $file ) or die "Can't open $file: $!";
+    open( FILE, ">$file" ) or die "Can't open $file: $!";
     print FILE $myhead;
     print FILE $start, ( $OPT{'w'} ? " -w" : "" ),
 	       "\n#line ", ($headlines+1), "\n" unless $linedone;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants