Java Reference
In-Depth Information
When you compile and run it, the appropriate editor window appears:
$ javac -d . ExecDemoSimple.java
$ java otherlang.ExecDemoSimple # causes a KWrite window to appear.
$
This version of exec() assumes that the pathname contains no blanks because these break
proper operation of the StringTokenizer . To overcome this potential problem, use an over-
loaded form of exec() , taking an array of strings as arguments. Example 24-1 runs the Win-
dows or Unix version of Netscape, assuming Netscape was installed in the default directory.
It passes the name of a help file as an argument, offering a kind of primitive help mechanism,
as displayed in Figure 24-1 .
Example 24-1. ExecDemoNS.java
public
public class
class ExecDemoNS
ExecDemoNS extends
extends JFrame {
private
private static
static final
final String NETSCAPE = "netscape" ;
/** The name of the help file. */
protected
protected final
final static
static String HELPFILE = "./help/index.html" ;
/** A stack of process objects; each entry tracks one external running process */
Stack < Process > pStack = new
new Stack <>();
/** main - instantiate and run */
public
public static
throws Exception {
String program = av . length == 0 ? NETSCAPE : av [ 0 ];
new
static void
void main ( String av []) throws
new ExecDemoNS ( program ). setVisible ( true
true );
}
/** The path to the binary executable that we will run */
protected
protected static
static String program ;
/** Constructor - set up strings and things. */
public
public ExecDemoNS ( String prog ) {
super
super ( "ExecDemo: " + prog );
String osname = System . getProperty ( "os.name" );
iif ( osname == null
null )
new IllegalArgumentException ( "no os.name" );
iif ( prog . equals ( NETSCAPE ))
program = // Windows or UNIX only for now, sorry Mac fans
( osname . toLowerCase (). indexOf ( "windows" )!=- 1 ) ?
"c:/program files/netscape/communicator/program/netscape.exe" :
"/usr/local/netscape/netscape" ;
throw
throw new
Search WWH ::




Custom Search