Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Kathe

macrumors newbie
Original poster
Sep 19, 2008
10
0
Hi All,

Im writing Java in XCode.
Can somebody provide me with the code snippets for calling an applications exe (say Microsoft word or Adobe InDesign etc)from Java swings.

Thanks
Kathe
 

garethlewis2

macrumors 6502
Dec 6, 2006
277
1
ProcessBuilder and Runtime.exec.

Look at those two in the Java documentation. That is all you will need to know to launch an application from inside Java.
 

Kathe

macrumors newbie
Original poster
Sep 19, 2008
10
0
Thanks for ur reply.

I triied the following code to open word 2004 application

Runtime.getRuntime().exec("open /Applications/Microsoft Ofiice 2004/Microsoft Word")

But this is not opening the Word exe since the folder name "Microsoft Ofiice 2004"contains space in between.

How to go about this
 

Guiyon

macrumors 6502a
Mar 19, 2008
771
4
Cambridge, MA
Thanks for ur reply.

I triied the following code to open word 2004 application

Runtime.getRuntime().exec("open /Applications/Microsoft Ofiice 2004/Microsoft Word")

But this is not opening the Word exe since the folder name "Microsoft Ofiice 2004"contains space in between.

How to go about this

First of all, I'd double check your spelling of 'Office'. As for the spaces, since they are being passed to the open command you will need to escape them for it to work properly; adding a '\\' (reduces down to a single '\' after compilation) before each space OR adding a '\"' to either side of the path should work.
 

Kathe

macrumors newbie
Original poster
Sep 19, 2008
10
0
Hi,

I tried the following,but it did not work

Runtime.getRunTime().exec("open /Applications/Microsoft\\Ofiice\\2004/Microsoft\\Word")

I tried this too ,but did not work

Runtime.getRunTime().exec("open /Applications/Microsoft Ofiice 2004/Microsoft Word/")

Can u pls code the correct way of using this
 

Sijmen

macrumors 6502a
Sep 7, 2005
709
1
Hi,

I tried the following,but it did not work

Runtime.getRunTime().exec("open /Applications/Microsoft\\Ofiice\\2004/Microsoft\\Word")

I tried this too ,but did not work

Runtime.getRunTime().exec("open /Applications/Microsoft Ofiice 2004/Microsoft Word/")

Can u pls code the correct way of using this

Any of these two:
Code:
Runtime.getRunTime().exec("open /Applications/Microsoft\\ Office\\ 2004/Microsoft\\ Word.app");
Runtime.getRunTime().exec("open \"/Applications/Microsoft Office 2004/Microsoft Word.app\"");

In the first version, every space is escaped for the shell. This is done with the \ character. Because that character is reserved in Java strings, you'll have to espace it so it becomes \\. The mistake you made with your version was leaving the spaces out.

In the second version, the path is quoted so the open command gets it as one parameter. The " is escaped using \ because it would otherwise end the string.

By the way, as noted earlier you misspelled Office in that path, and .app is parth of the name of that directory. Also I think it isn't a very good idea to hardcode paths to apps.

And you should have been able to find this out by yourself, really.
 

mpcoder

macrumors newbie
Mar 21, 2009
16
0
I've been trying to have a java application open a quicktime video, but its not working.

I've tried:
Runtime.getRuntime().exec("open \"/Applications/QuickTime Player.app\"");

but no dice...

any ideas why?
 

venski

macrumors newbie
Apr 30, 2009
1
0
You can try the following:
Code:
String params[] = {
	"open",
	"/Applications/Microsoft Office 2004/Microsoft Word.app"
};
Runtime.getRunTime().exec(params);
This way you tell the JVM to pass the second string as a parameter to the open executable, and it takes care of escaping it in a proper way.

It worked alright for me.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.