ProcessBuilder and non-applications

Hi,

I am trying to use processbuilder to open up applications from within my program. I am having a slight problem that I don't know of an easy way to fix.

Imagine this:

I have a program that allows me to browse the contents of my disk. I then click on "test.doc". I select this and then MS Word should start and load test.doc.

The problem is that when I use process builder to this file, it gives me an error of 193. So I have to tell it to open up MS Word with test.doc. The problem is that, I would have to do this for EVERY TYPE OF FILE! It would be extremely difficult for me to program all of that code in. So is there an easier way to tell Windows (and any other OS for that matter) to choose the right program to open automatically?

Thank you

[788 byte] By [dayrinni] at [2007-11-26 12:03:53]
# 1
If I understand what you're asking...There's a Windows utility (or something) called "start" that might do what you need. Go to a command window and type "help start" for more info, or see if maybe there's a help doc created for it.
paulcw at 2007-7-7 12:29:36 > top of Java-index,Java Essentials,Java Programming...
# 2

Thank you for your assistance.

I am having a slight problem with the code for process builder. Your start idea works fine in a dos prompt.

Here is my code:

Process pb = new ProcessBuilder("start " + "C:\\test\\repeats.txt").start();

When I run the program this is my output:

java.io.IOException: CreateProcess: "start C:\test\repeats.txt" error=2

This works fine in the dos prompt. I'm not sure what the problem is.

I would like to also say that this works:

Process pb = new ProcessBuilder("C:\\WINNT\\notepad.exe", "C:\\test\\repeats.txt").start();

Any help?

Thanks.

Message was edited by:

dayrinni

dayrinni at 2007-7-7 12:29:36 > top of Java-index,Java Essentials,Java Programming...
# 3

/snip/

> I then click on "test.doc". I select this and then MS Word should start and load test.doc.

/snip/

You are wanting to use Windows' file associations information when you do this. However, Java doesn't do that. Java requires that the object of the methods of Runtime and ProcessBuilder is a valid operating system command. Which commands are valid is system-dependent,.

I think that file association recognition is implemented in Java 6

ChuckBing at 2007-7-7 12:29:36 > top of Java-index,Java Essentials,Java Programming...
# 4
"start" might actually be a feature of the shell in question (cmd.exe) rather than a separate utility.You might have to do something like:"cmd.exe [args] start [file]"Try googling "cmd" and "start" and see what you get.
paulcw at 2007-7-7 12:29:36 > top of Java-index,Java Essentials,Java Programming...