Operating System - HP-UX
1820041 Members
3282 Online
109608 Solutions
New Discussion

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

 
srikanth.259
Occasional Advisor

Problem in getting cmd line agruments on korean HPUX 11.11 machine

Hi all,

I am using HPUX11.11 machine to get command line arguments in korean text with following code

// Locale set to ko_KR.eucKR
pid = atoi(argv[1]);
pu.pst_command = long_command;
if (pstat(PSTAT_GETCOMMANDLINE, pu, MAX_LENGTH, 1, pid) != -1) {

// converting pu.pst_command to wide char using mbstowcs()
//returning wide char
}

but wide char contains garbled value ...

can someone help me on this

or i am using wrong api ...

Thxn in advance

Srikanth
14 REPLIES 14
Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

Have you tried using this function on itself to check if it works for ascii?
Have you set the proper locale?
Have you looked at the raw hex values in pst_command and with argv in that process?
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

displays the ascii values correctly. proper locale is set.
Plz let me know how to check for the hex values.
Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>let me know how to check for the hex values.

You can loop though each unsigned char in pst_command and print in hex:

const unsigned char *p = (const unsigned char*)pu.pst_command;
for (; p; ++p)
printf("%02x ", *p);
printf("\n");
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

Hi Dennis,

Iterated thru pst_command , the raw hex are correct.

The issue is with mbstowcs() method.

here is the code ......

setLocale(LC_TYPE,"ko_KR.eucKR");
pu.pst_command = long_command;
wchar_t *wideCharString;
size_t size;
char *strCmdMatch;
strCmdMatch = (char *) malloc ((sizeof (char)) * MAX_LENGTH);
memset (strCmdMatch, '\0', (sizeof (char)) * MAX_LENGTH);
if (pstat(PSTAT_GETCOMMANDLINE, pu, MAX_LENGTH, 1, pid) != -1) {

// converting pu.pst_command to wide char using mbstowcs()for using in java code
int requiredSize = strlen(strCmdMatch);
wideCharString = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t ));
size = mbstowcs( wideCharString,strCmdMatch, requiredSize+1);

//returning wide char to java using NewString()
}

mbstowcs () is not converting multibyte char to wide char string properly

Plz help me ............

~ Srikanth
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

Sorry mistake in above reply ..... here is the correct one


Hi Dennis,

Iterated thru pst_command , the raw hex are correct.

The issue is with mbstowcs() method.

here is the code ......

setLocale(LC_TYPE,"ko_KR.eucKR");
pu.pst_command = long_command;
wchar_t *wideCharString;
size_t size;


if (pstat(PSTAT_GETCOMMANDLINE, pu, MAX_LENGTH, 1, pid) != -1) {

// converting pu.pst_command to wide char using mbstowcs()for using in java code
int requiredSize = strlen(pu.pst_command);
wideCharString = (wchar_t *)malloc( (requiredSize + 1) * sizeof( wchar_t ));
size =mbstowcs(wideCharString,pu.pst_command,requiredSize+1);

//returning wide char to java using NewString()
}

mbstowcs () is not converting multibyte char to wide char string properly

Plz help me ............

~ Srikanth
Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>Iterated thru pst_command, the raw hex are correct.

Can you provide the values?
What is the return value of mbstowcs?
What codeset is java using?
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>>Can you provide the values?

76 69 20 c7 d1 b1 db

>> What is the return value of mbstowcs?

strlen(pu.pst_command)=7
return value of mbstowcs() is bytes req to convert mbstowcs (5 in my case)

>> What codeset is java using?
windows w2k3 korean OS with codeset MS949

Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>76 69 20 c7 d1 b1 db

This is: vi ??
$ a.out
locale==ko_KR.eucKR
codeset(62) is eucKR
size: 5
str: vi úîà Ã
wstr: vi úîà Ã
00000076 00000069 00000020 0000c7d1 0000b1db

So the wchar_t value is just the two byte value.

>windows w2k3 korean OS with codeset MS949

What wchar_t value do you thinks these should have?
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

wchat_t value should be vi
Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>wchat_t value should be vi

Yes, I guessed that. :-)
The value you are getting is that value. Your problem is that you need to convert that character encoding to java's.
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>> The value you are getting is that value.

No , i am not getting the expected value i.e the file name @ cmd line , its garbled

>>Your problem is that you need to convert that character encoding to java's.

if i convert the string to wchar_t , the iss ue will be solved i.e mbstowcs takes care pf conversion
Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

>I am not getting the expected value i.e the file name @ cmd line, it's garbled

Please convert the correct name to hex and attach:
echo korean_filename | xd -tx1

>if i convert the string to wchar_t, the issue will be solved i.e mbstowcs takes care pf conversion

I printed the original hex string you provided, with %s and the wchar_t string with %ls and I got the same thing.
srikanth.259
Occasional Advisor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

output:
> echo à à ±à | xd -tx1
0000000 c7 d1 b1 db a
0000005
Dennis Handly
Acclaimed Contributor

Re: Problem in getting cmd line agruments on korean HPUX 11.11 machine

> echo à  à  à ±à  | xd -tx1
0000000 c7 d1 b1 db a

This indicates everything is working. You have the right command line and you have the right wchar_t string. But you may have the wrong codeset for windows.

That's assuming when you do a "ls à  à  à ±à " it finds the file.