correctly setting system environment variables before calling Process.exec

  • Thread starter Aryeh M. Friedman
  • Start date
A

Aryeh M. Friedman

I have a program that needs to set the DISPLAY environment variable before calling an external program so it will display correctly on remote X-Windows machines. Note I *DO NOT* want it to be headerless i.e. I specifically can not and should not do java -Djava.awt.headless=true. The reason is the program *MUST* run in a interactive xterm on the remote machine. Here is something I tried with a no go:

import java.util.*;

public class Foo
{
public static void main(String[] args)
throws Throwable
{
Set<Map.Entry<String,String>> env=System.getenv().entrySet();
String[] envOut=new String[env.size()+1];

int i=0;
for(Map.Entry<String,String> e:env)
envOut[i++]=e.toString();

envOut="DISPLAY=192.168.0.2:0.0";

Runtime.getRuntime().exec("xterm",envOut);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top