Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^4: How can I get a Unicode @ARGV?

by Anonymous Monk
on Aug 31, 2012 at 08:57 UTC ( [id://990952]=note: print w/replies, xml ) Need Help??


in reply to Re^3: How can I get a Unicode @ARGV?
in thread How can I get a Unicode @ARGV?

Ok, I did some testing with PAR Packager, version 1.013 (PAR version 1.005)

 pp -M strict -M warnings -M Data::Dump -M Win32::Unicode::Native -M Win32::Process::CommandLine -M Win32::CommandLine   dragdropmeargv.pl

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump; dd \@ARGV; eval 'use Win32::Unicode::Native;'; dd \@ARGV; { use Win32::Process::CommandLine; Win32::Process::CommandLine::GetPidCommandLine($$, my $str); dd $str; } use Win32::CommandLine(); dd [ Win32::CommandLine::argv() ]; dd [ Win32::CommandLine::command_line() ]; #~ scalar <>; sleep 10;

But the results were disappointing, no unicode

[ "utf-filedir\\kebab\\cevap.txt", "utf-filedir\\kebab\\ra\x9Enjic.txt", "utf-filedir\\kebab\\???????.txt", "utf-filedir\\kebab\\??????.txt", "utf-filedir\\kebab\\?????.txt", "utf-filedir\\kebab\\????.txt", "utf-filedir\\kebab\\ra\x9Enjic", "utf-filedir\\kebab\\cevap.txt", ] [ "utf-filedir\\kebab\\cevap.txt", "utf-filedir\\kebab\\ra\x9Enjic.txt", "utf-filedir\\kebab\\???????.txt", "utf-filedir\\kebab\\??????.txt", "utf-filedir\\kebab\\?????.txt", "utf-filedir\\kebab\\????.txt", "utf-filedir\\kebab\\ra\x9Enjic", "utf-filedir\\kebab\\cevap.txt", ] "utf-filedir\\a.exe utf-filedir\\kebab\\cevap.txt utf-filedir\\kebab\\ +raznjic.txt utf-filedir\\kebab\\???????.txt utf-filedir\\kebab\\????? +?.txt utf-filedir\\kebab\\?????.txt utf-filedir\\kebab\\????.txt utf- +filedir\\kebab\\raznjic utf-filedir\\kebab\\cevap.txt" [ "utf-filedir\\kebab\\cevap.txt", "utf-filedir\\kebab\\ra\x9Enjic.txt", "utf-filedir/kebab/RANJI~1.TXT", "utf-filedir/kebab/0CA1~1.TXT", "utf-filedir/kebab/35AA~1.TXT", "utf-filedir/kebab/531D~1.TXT", "utf-filedir/kebab/DD0B~1.TXT", "utf-filedir/kebab/EVAP~1.TXT", "utf-filedir/kebab/cevap.txt", "utf-filedir\\kebab\\????.txt", "utf-filedir\\kebab\\ra\x9Enjic", "utf-filedir\\kebab\\cevap.txt", ] [ "utf-filedir\\a.exe utf-filedir\\kebab\\cevap.txt utf-filedir\\kebab +\\ra\x9Enjic.txt utf-filedir\\kebab\\???????.txt utf-filedir\\kebab\\ +??????.txt utf-filedir\\kebab\\?????.txt utf-filedir\\kebab\\????.txt + utf-filedir\\kebab\\ra\x9Enjic utf-filedir\\kebab\\cevap.txt", ]

Replies are listed 'Best First'.
Re^5: How can I get a Unicode @ARGV?
by exilepanda (Friar) on Aug 31, 2012 at 13:46 UTC
    Inspired from your test result, I am really wondering if that's the encoding problem or if the argv actually turned into ANSI before pipe to my perl script...

    I've wrote a little more in reply to a upper thread. http://www.perlmonks.org/?node_id=991005 Do you think this can mean something ?

    Though, thank you very much for the help test! =)

      Supposedly this is the same as using wmain, but works with mingw

      # define UNICODE # define _UNICODE #include <windows.h> #include <stdio.h> #include <shellapi.h> int __cdecl main() { LPWSTR *szArglist; int nArgs; int i; int ix; int nLength; wprintf(L"commandline==\n%ws\n====\n\n\n", GetCommandLineW() ); szArglist = CommandLineToArgvW(GetCommandLineW(), &nArgs); if( NULL == szArglist ) { wprintf(L"CommandLineToArgvW failed\n"); return 0; } else { for( i=0; i<nArgs; i++) printf("%d: %ws\n", i, szArglist[i]); for( i=0; i<nArgs; i++) wprintf(L"\n\n%d: %s\n", i, szArglist[ +i]); //~ http://stackoverflow.com/questions/4014172/wprintf-format-type-spe +cification-ws# c++ - wprintf format type specification %ws - Stack Ov +erflow //~ http://msdn.microsoft.com/en-us/library/ms647550%28VS.85%29.aspx# + wsprintf function (Windows) for( i=0; i<nArgs; i++) { nLength = wcslen( szArglist[i] ); //~ printf("\n{%d: nLength %d}\n", i, nLength ); printf("\n$F[%d] = []; # nLength %d\n", i, nLength ); for( ix=0; ix < nLength; ix++ ){ //~ printf("%d: %d %#04X\n", i, ix, szArglist[i][ix] ) +; //~ printf("{%d: %d %#04X} ", i, ix, szArglist[i][ix] +); printf("$F[%d][%d]=%#04X; ", i, ix, szArglist[i][ix] ) +; if( 0 == (ix % 5) ) { printf("\n"); } } } } // Free memory allocated for CommandLineToArgvW arguments. LocalFree(szArglist); //~ sleep(20); printf("\n"); system("PAUSE"); return(1); }

      And I do appear to get some kind of unicode :)

      $F[1] = []; # nLength 39 $F[1][24]=0X6B; $F[1][25]=0X65; $F[1][26]=0X62; $F[1][27]=0X61; $F[1][28]=0X62; $F[1][29]=0X5C; $F[1][ +30]=0X107; $F[1][31]=0X65; $F[1][32]=0X76; $F[1][33]=0X61; $F[1][34]=0X70; $F[1][ +35]=0X2E; $F[1][36]=0X74; $F[1][37]=0X78; $F[1][38]=0X74; $F[2][24]=0X6B; $F[2][25]=0X65; $F[2][26]=0X62; $F[2][27]=0X61; $F[2][28]=0X62; $F[2][29]=0X5C; $F[2][ +30]=0X72; $F[2][31]=0X61; $F[2][32]=0X17E; $F[2][33]=0X6E; $F[2][34]=0X6A; $F[2] +[35]=0X69; $F[2][36]=0X107; $F[2][37]=0X2E; $F[2][38]=0X74; $F[2][39]=0X78; $F[2] +[40]=0X74; binmode STDOUT, ':encoding(UTF-8)'; fudge(\@F); use Data::Dump; dd\@F; sub fudge { my( $args ) = @_; for my $arg ( @$args ){ next unless defined $arg; my $one = ""; for my $char ( @$arg ){ next unless defined $char; my $chr = chr( $char ); print $chr; $one .= $chr; } print "\n"; dd $one; } } __END__ kebab\&#263;evap.txt "kebab\\\x{107}evap.txt" kebab\ražnji&#263;.txt "kebab\\ra\x{17E}nji\x{107}.txt"

      Now all that is left is to figure out how to call system() in C

Re^5: How can I get a Unicode @ARGV? ( Win32::CommandLine bug )
by Anonymous Monk on Dec 07, 2012 at 04:51 UTC

    Win32::CommandLine doesn't actually use unicode calls, you need to compile it with

    #define UNICODE #define _UNICODE

    Then it'll probably work

    Although it should probably use GetCommandLineW explicitly

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-25 04:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found