File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Runtime.getRuntime().exec( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Runtime.getRuntime().exec("sh export LC_ALL=C") fails!!!!!!!!!!" Watch "Runtime.getRuntime().exec("sh export LC_ALL=C") fails!!!!!!!!!!" New topic
Author

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

Manimekala Velautham
Greenhorn

Joined: May 31, 2006
Posts: 16
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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?


[Jess in Action][AskingGoodQuestions]
Manimekala Velautham
Greenhorn

Joined: May 31, 2006
Posts: 16
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

Use the standard C library "setlocale()" function in your native code.
Manimekala Velautham
Greenhorn

Joined: May 31, 2006
Posts: 16
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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

Joined: May 31, 2006
Posts: 16
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

Joined: Jul 08, 2003
Posts: 24184
    
  34

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

Joined: May 31, 2006
Posts: 16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Runtime.getRuntime().exec("sh export LC_ALL=C") fails!!!!!!!!!!