Shell Execute and Java

I found that Windows’ ShellExecute (in the Win32 API) could be very useful, especially in the noddy VB6 applications I keep being asked to write.

Anyway, I was looking at doing something similar in Java.

This only works in Windows – but basically, you rely on the Windows performing it’s default action…
import java.lang.*;
public class OpenDocument {
public static void main (String [] Args ) {
System.out.println("Main:");
Process oProcess;
String cmd[] = { "cmd" , "/c", "start" , "C:\Java\OpenDocument\Hamlet.doc"};
try {
oProcess = Runtime.getRuntime().exec( cmd );
} catch ( Exception e ) {
System.out.println(e.toString());
}
}
}

In this case, the programme ‘starts’ a word document – that is, it opens up Word and loads in the document. This is done via the command prompt. Nuff said.

Advertisement
Shell Execute and Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.