27.04.2013 Views

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

330 Java Tips.pdf - FTP Server

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Operational Systems & <strong>Java</strong><br />

Answer: You must create a C/C++ program that call directly the<br />

NotifyIcon API to display/manage the Icon in the Systray. Then<br />

call the program from <strong>Java</strong> with JNI.<br />

Currently I'm running two operating systems on one machine, Windows 2000 and<br />

Windows ME...<br />

Currently I'm running two operating systems on one machine, Windows 2000 and<br />

Windows ME.<br />

Windows ME runs on default, Windows 2000 is on D drive and ME is on C drive. I<br />

tried to add the JDK directory to the classpath but there isn't a autoexec.bat on the D<br />

directory, but there is one for C.<br />

Should I just create a autoexec.bat for D?<br />

Answer: Go to Settings/Control Panel/System/Advanced/Environment Variables...<br />

and<br />

edit your CLASSPATH variable if exists or add a new one.<br />

I need to be able to run a shell script from java, by doing a host call to unix. I am<br />

currently trying 'Runtime.exec' to do this. It says it runs it, but doesn't actually<br />

successfully complete the command (which is a file delete).<br />

I need to be able to run a shell script from java, by doing a host call to unix. I am<br />

currently trying 'Runtime.exec' to do this. It says it runs it, but doesn't actually<br />

successfully complete the command (which is a file delete).<br />

A few questions I have about this:<br />

1. Can I trace it or something to see why it isn't working?<br />

2. How can I get the 'return code' from the shell script?<br />

3. Will the java procedure wait for the shell script to execute, or does<br />

it run a seperate thread concurrently?<br />

Answer: > 1. Can I trace it or something to see why it isn't working?<br />

Runtime.exec() returns a Process object that you can get information from.<br />

If the script is written with sh or some derivate thereof you can do 'set -x' in the script<br />

to trace its behaviour. For other scripting languages there is likely a similar<br />

mechanism. To see the trace in your <strong>Java</strong> program, read from the error or output<br />

streams of the process (Process.getErrorStream() or Process.getOutputStream()).<br />

It's possible that the script is already printing a message to its error stream that you<br />

aren't seeing, indicating why it isn't working.<br />

Answer: > 2. How can I get the 'return code' from the shell script?<br />

Call Process.exitValue().<br />

Answer: > 3. Will the java procedure wait for the shell script to execute, or does it run<br />

a seperate thread concurrently?<br />

The program runs concurrently in a separate *process*, not a thread within the JVM.<br />

To wait for the process to finish, call Process.waitFor().<br />

Are not-initializable classes and methods like System.out.println() and<br />

Math.random() "synchronized" ?<br />

Answer: I think they are synchronized. Simple observation: did you ever see once<br />

file:///F|/350_t/350_tips/os_win_linux.htm (2 of 8) [2002-02-27 21:18:56]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!