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

Miss Mandy Mac

macrumors newbie
Original poster
Apr 30, 2007
21
0
I am having a problem launching textedit from a Java application. It was working a week ago on a fresh iMac, but since then I have installed CS2, the Macromedia Studio MX suite, and some other programs and now the textedit program does not start from my Java app. This is the code that I am using in my application to launch textedit:

Code:
String command = "open -e \""+filename.getAbsolutePath()+"\"";
Runtime rt = Runtime.getRuntime();
rt.exec(command);

I've also tried it this way:
Code:
String command = "open -e \""+filename.getAbsolutePath()+"\"";
Process child = Runtime.getRuntime ().exec (command);

I've printed the command to execute out on the console and it appeared like this:
Code:
open -ef "\Users\user\Desktop\filename.txt"
But it doesn't open textedit. The funny thing is, if I copy and paste that open command into the Terminal, it will open the file in TextEdit. Why won't it work in my Java app anymore, but still work through the terminal? I don't get any errors in the console, it just doesn't open TextEdit anymore. Is there a setting somewhere that might have been changed that let me start TextEdit from a Java app. I checked and TextEdit is still my default program for opening text files, which I guess makes since why it works from the Terminal, but I don't get why it doesn't start TextEdit from my Java app.

I'm using Java 1.5.0_07. Thanks for your help :)
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
A few things to try spring to mind:

  1. Use the full path for open: /usr/bin/open
  2. Specify the application to open, just in case something else gets accosiated with the file via -b com.apple.TextEdit
 

Miss Mandy Mac

macrumors newbie
Original poster
Apr 30, 2007
21
0
My mistake, the problem wasn't opening textedit. I found I was doing that correctly, the problem was the file I was trying to open with textedit. The filepath to the file had spaces in it, and it will not open if either the file itself, or the folders it's contained in have spaces in them. It was working when I ran this program in a Windows environment, so I'm not sure what the difference is on a Mac. I do know that I contained my filepath with quotes as you can see in my previous post. Is there something special I need to do with the spaces in the file path other than put quotes around the path to my file?
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
It shouldn't work on Windows or any other OS either. You need to use a different exec method. The one you are using splits the string you provide on whitespace characters and passes that to )]this mehod. You cannot alter that behaviour. So you need to call the other method with the split of commands and arguments you want.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.