Operating System - HP-UX
1833013 Members
2845 Online
110048 Solutions
New Discussion

Java code to launch browser on HP-UX 11.0

 
SOLVED
Go to solution

Java code to launch browser on HP-UX 11.0

Does anyone know why the following java code will not launch the netscape browser?

Runtime.getRuntime().exec(cmd)
where
cmd = netscape http://somepage.com

Netscape is located in /opt/netscape and this is in my PATH variable and it is set to my default web browser for NNM. Is there anything I am missing, such as a patch or something? I'm using HP-UX 11.0 and Netscape 4.79 JRE 1.4.0.01

I have code similar to that above where cmd = netscape -remote openURL(http://somepage.com) This displays my web page OK as long as the browser is already open.

Thanks
7 REPLIES 7
Michael Elleby III_1
Trusted Contributor

Re: Java code to launch browser on HP-UX 11.0

Hello-

Quick questions-

- Are you getting any errors on the screen when this code is executed?

- Is your environment variable (DISPLAY) set when this code is executed?

Mike
Knowledge Is Power

Re: Java code to launch browser on HP-UX 11.0

Mike,

Yes, the DISPLAY variable is set. DISPLAY=lucy:0.0

I am catching the exception, "process hasn't exited" using the following code fragment:

Process p = Runtime.getRuntime().exec(cmd);

try{
exitCode = p.exitValue();
}
catch(IllegalThreadStateException itse){
}

note: cmd=netscape http://somepage.com

Thanks
Anonymous
Not applicable

Re: Java code to launch browser on HP-UX 11.0

as the nescape remote interface is "not that handy" you may want to build a wrapper that does what you would expect on the command line.

example:
$ cat $HOME/bin/url
LOG=$HOME/.`basename $0`.log
NOW=`date '+%y%m%d_%H%M%S'`
echo $NOW $* >> $LOG
echo $* #>2&
date #>2&
if [ X$DISPLAY = X ] ; then export DISPLAY=$IP:0.0 ; fi
/opt/netscape/netscape -install -display $DISPLAY -remote "openURL ( $* ,new-window)"
#The End.
$url www.hp.com #opens a new browser window with http://www.hp.com

taking this a step further you may have
$cat google
url www.google.com
#The End.
$

you get the idea... not sure if that really helps for java- however, worth to try.
Michael Armbrecht
Frequent Advisor

Re: Java code to launch browser on HP-UX 11.0

Hi Ken,

the "process has not exited" error is logical (and means netscape is still running). There is either something wrong in your DISPLAY or your PATH variable. Try to put them in your code, or use a wrapper script as Thomas suggested (good idea, actually). It is also safer to pass the exec() method a string array containing the options passed to the program you want to start.

The attached code worked on my system - it opens netscape with the URL "http://www.hp.com".

Hope it helps...
Michael
Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.

Re: Java code to launch browser on HP-UX 11.0

Hi Michael,

I've tried your code and I get the same behavior as I do with my code, (i've added process.waitfor() to eliminate the exception). In other words, it loads the web page when the browser is up, but seems to do nothing if the browser is not up, including no errors.

The same code works fine on a Solaris machine, so I don't think it is a Java issue. I think the problem might be with a path/environment setting or perhaps a patch that has to be installed.

Anyone have any other recommendations? Are others using the same OS? HP-UX 11.0, Netscape 4.79, JRE 1.4

Regards,

ken
Michael Armbrecht
Frequent Advisor
Solution

Re: Java code to launch browser on HP-UX 11.0

Hi Ken,

I tried it again on a different HP-UX machine and it didn't open netscape there, either. The only way to make it work was making a script calling netscape with the necessary parameters (display, URL) and call this script (startnetscape.sh) from the java program. That definitely worked. This seems to be an issue specifically with netscape, though. Starting e.g. xclock directly from the java program was no problem.

Regards
Michael
Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic.

Re: Java code to launch browser on HP-UX 11.0


I did some testing by getting the input stream from the runtime process used to call netscape from the Java code. I received an error that said I should check the XFILESEARCHPATH, XUSERFILESEARCHPATH, and one other variable (i'm at home right now so I don't recall the name). Anyway, I did an echo $var on all three and none were set. I tried adding them to my .dtprofile and setting the path to netscape, but it still didn't work.

I switched to using Netscape 6.2 and all is well now. I am able to launch the browser with my original Java code. One difference: on Netscape 4.79, if the process fails (browser not open), the exitValue() returns a value other than 0 (1). On Netscape 6.2, when the process fails (browser not open), the exitValue() returns 0. So, just have to code for those differences.

Regards, and thanks for everyone's help