Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.89k stars 533 forks source link

Buggy parsing of script arguments in windows #10421

Closed p5pRT closed 14 years ago

p5pRT commented 14 years ago

Migrated from rt.perl.org#75530 (status was 'rejected')

Searchable as RT75530$

p5pRT commented 14 years ago

From alexandrfedorov@gmail.com

Created by alexandrfedorov@gmail.com

There is a problem with parsing command line arguments in Perl in windows​:

for example this command in cmd.exe​:

perl -E "say join qq(\n)\,@​ARGV" "123 234\" 123

resulting​:

123 234" 123

but it must be​:

123 234\ 123

Why it's important? Because filepath separator in windows is "\" and i can't use long filepaths or UNC in arguments of scripts (for example " \\server\share\some \<file​://server/share/some> folder\")

Perl Info ``` Flags: category=core severity=medium Site configuration information for perl 5.12.0: Configured by 1 at Wed Apr 28 20:49:19 2010. Summary of my perl5 (revision 5 version 12 subversion 0) configuration: Platform: osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread uname='Win32 strawberryperl 5.12.0.0 #1 Wed Apr 28 11:51:06 2010 i386' config_args='undef' hint=recommended, useposix=true, d_sigaction=undef useithreads=define, usemultiplicity=define useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=undef, use64bitall=undef, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='gcc', ccflags =' -s -O2 -DWIN32 -DHAVE_DES_FCRYPT -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fno-strict-aliasing -mms-bitfields -DPERL_MSVCRT_READFIX', optimize='-s -O2', cppflags='-DWIN32' ccversion='', gccversion='4.4.3', gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234 d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='long long', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='g++', ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"' libpth=C:\strawberry\c\lib C:\strawberry\c\i686-w64-mingw32\lib 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=libperl511.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' ' cccdlflags=' ', lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"' Locally applied patches: @INC for perl 5.12.0: C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib . Environment for perl 5.12.0: HOME (unset) LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\strawberry\c\bin;C:\strawberry\perl\bin;C:\Program Files\Git\cmd;C:\WINDOWS\system32\WindowsPowerShell\v1.0;C:\strawberry\perl\site\bin;Z:\Software\Tools\Sysinternals\pstools;I:\programz\utils PERL_BADLANG (unset) SHELL (unset) ```
p5pRT commented 14 years ago

From @demerphq

On 3 June 2010 07​:50\, AlexandrFedorov \perlbug\-followup@&#8203;perl\.org wrote​:

# New Ticket Created by  AlexandrFedorov # Please include the string​:  [perl #75530] # in the subject line of all future correspondence about this issue. # \<URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=75530 >

This is a bug report for perl from alexandrfedorov@​gmail.com\, generated with the help of perlbug 1.39 running under perl 5.12.0.

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

There is a problem with parsing command line arguments in Perl in windows​:

for example this command in cmd.exe​:

perl -E "say join qq(\n)\,@​ARGV" "123 234\" 123

resulting​:

123 234" 123

but it must be​:

123 234\ 123

Why it's important? Because filepath separator in windows is "\" and i can't use long filepaths or UNC in arguments of scripts (for example " \\server\share\some \<file​://server/share/some> folder\")

This isnt a bug in perl. Perl doesnt parse the command line cmd.exe does. And microsoft has never been forthcoming of the actual rules involved\, and despite much time wasted by many people\, including me\, nobody really knows *exactly* what the rules are. Probably because there arent any rules\, just a nasty mess of exceptions.

Anyway\, there are workarounds. You could for instance do either of these​:

perl -E "say join qq(\n)\,@​ARGV" 123" "234\ 123 perl -E "say join qq(\n)\,@​ARGV" "123 234"\ 123

But a much simpler solution is to not use backslashes for path separators and use forward slashes. Perl\, and IIRC the underlying windows API calls that Perl uses work just fine with forward slashes.

Anyway\, IMO this is not a bug in Perl\, and the ticket should be closed.

Yves

-- perl -Mre=debug -e "/just|another|perl|hacker/"

p5pRT commented 14 years ago

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

p5pRT commented 14 years ago

From alexandrfedorov@gmail.com

Hello\, you were right! It's not a Perl problem\, it's gcc problem i tried such code​:

#include \ int main ( int argc\, char *argv[]\, char *envp[] ) {   std​::cout \<\< "you have " \<\< argc \<\< " arguments"; }

resulting​:

a.exe "a a" you have 2 arguments a.exe "a a" a you have 3 arguments a.exe "a a\" a you have 2 arguments

P.S. changing \ to / is a very bad workaround\, because newbies is hard to understand and hard to use this. I'll try to fix this problem in gcc.

p5pRT commented 14 years ago

alexandrfedorov@gmail.com - Status changed from 'open' to 'resolved'

p5pRT commented 14 years ago

@iabyn - Status changed from 'resolved' to 'rejected'