Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Parsing Windows CommandLine from Perl

by Anonymous Monk
on Apr 17, 2015 at 19:07 UTC ( [id://1123812]=note: print w/replies, xml ) Need Help??


in reply to Parsing Windows CommandLine from Perl

Whats this now eyepopslikeamosquito??

<update> yes I have "use Data::Dump;" loaded form sitecustomize, you can set PERL5OPT=-MData::Dump to get same effect of dd() available

</update>

$ perl -e " dd\@ARGV " -- "ro""shambo" ["ro\"shambo"] $ perl -e " dd\@ARGV " "ro""shambo" ["ro\"shambo"]

Seems to me "" works fine, and its not perl thats messing with it :)

$ perl -MDevel::PL_origargv -e" dd( Devel::PL_origargv->get ) " "ro""s +hambo" "ro "" shambo" ( "D:\\perl\\citrusperl\\bin\\perl.exe", "-MDevel::PL_origargv", "-e dd( Devel::PL_origargv->get ) ", "ro\"shambo ro", "", "shambo", )

From inspired by Re^5: How can I get a Unicode @ARGV? ( Win32::CommandLine bug ) a patch for Win32 (compiles easy)

diff -ruN Win32-0.45/Win32.xs Win32-0.45066/Win32.xs --- Win32-0.45/Win32.xs 2012-08-13 16:06:21.000000000 -0700 +++ Win32-0.45066/Win32.xs 2012-12-08 06:46:20.593750000 -0800 @@ -1753,6 +1753,32 @@ XSRETURN_IV(SetConsoleOutputCP((int)SvIV(ST(0)))); } + + +XS(w32_ArgvW) +{ + dXSARGS; + + int nArgs; + int ix = 0; + wchar_t** szArglist; + const wchar_t* wArgstring = GetCommandLineW(); + + if (GIMME_V == G_ARRAY) { + szArglist = CommandLineToArgvW( wArgstring , &nArgs); + for( ix = 0; ix < nArgs; ix++) { + XPUSHs( wstr_to_sv(aTHX_ szArglist[ix] ) ); + } + PUTBACK; + return; + } else { + XPUSHs( wstr_to_sv(aTHX_ wArgstring ) ); + PUTBACK; + return; + } + XSRETURN_EMPTY; +} + MODULE = Win32 PACKAGE = Win32 PROTOTYPES: DISABLE @@ -1825,5 +1851,7 @@ #ifdef __CYGWIN__ newXS("Win32::SetChildShowWindow", w32_SetChildShowWindow, file); #endif + + newXS("Win32::ArgvW", w32_ArgvW, file); XSRETURN_YES; }

And it shows same results

$ perl -Mblib -MWin32 -e " dd( Win32::ArgvW() )" "ro""shambo" "ro "" + shambo " ( "perl", "-Mblib", "-MWin32", "-e", " dd( Win32::ArgvW() )", "ro\"shambo ro", "", "shambo", "", ) $ perl -Mblib -MWin32 -e " dd( scalar Win32::ArgvW() )" "ro""shambo" + "ro "" shambo " "perl -Mblib -MWin32 -e \" dd( scalar Win32::ArgvW() )\" \"ro\"\"sham +bo\" \"ro \"\" shambo \""

Seems to me "" works fine, and its not perl thats messing with it :) its cmd.exe ... not 100% sure about that but thats cmd.exe for you, its fudgy

link dump :)

See also

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1123812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found