• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime.getRuntime().exec("sh export LC_ALL=C") fails!!!!!!!!!!

 
Manimekala Velautham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to export the LC_ALL variable from Java to set the locale to C instead of other locales.

The command i want to run in HP-UX console is
"export LC_ALL=C"

I tried to execute the above command from a java program, but it did not give any error messages.But the locale is not changed to C.


Any input on this problem will greatly help me!!!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Welcome to JavaRanch!

The bash command "export X=Y" sets the variable X in the shell where it's called, and further, makes it available to all other processes started from that shell. By executing this command in a shell from Java, you're defining the variable in a shell that executes just this one command and then exits. So whereas the command works, it doesn't do anything!

There's no way for a child process to add something to its parent's environment. Why do you want to do this from a Java program?
 
Manimekala Velautham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thanks for your valuable suggestion.

My problem is

I am using JNI for writing logs.
When the locale is set to ja_JP.eucJP, JNI call for writing a syserrlog is printing some japanese characters instead of "Sep" in Timestamp.

If I run a standalone C program to print the date, it is printing in english though the locale is set to ja_JP.eucJP.

When you call the same C function to print the date through JNI, it is printing some junk chars for "Sep".So i want to change the locale "C" from my java program.

I tried Locale.setDefaultLocale(Locale.English)...but still my JNI call is printing some junk chars for "Sep". So i tried by changing the LC_ALL from java program with exec().

Java Code:


C Code:
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the standard C library "setlocale()" function in your native code.
 
Manimekala Velautham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
I have tried and it is working fine though the Locale is set to ja_JP.eucJP. But i want to do that from java. Is it possible?...Because, my native methods are shared my many applications.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manimekala Velauthyam:
Thanks.
I have tried and it is working fine though the Locale is set to ja_JP.eucJP. But i want to do that from java. Is it possible?


Sure. Write another native method!
 
Manimekala Velautham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my codebase,writing one more native method will also cause problem,Is there any way to solve this problem in java itself?..
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would writing another native method cause a problem? Can you create another class called "LocaleSetter" to hold this native method, and just use it in this one application?

But no, I don't believe there's any other way to accomplish what you want.
 
Manimekala Velautham
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I dropped the idea of doing that in java and I fixed that issue by keeping one more JNI call to set the Locale.

Thank you so much for spending your valuable time in this issue....
Timely Help...Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic