Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: trouble with open call



Sergiy Michka wrote:

I've run in several problemens using /usr/bin/open from my java application.

I have 2 general cases:

1: if external application is not defined:
Runtime.getRuntime().exec(new String[] { "/usr/bin/open", "my file name here" });
=> works


2: if external application is defined:
Runtime.getRuntime().exec(new String[] { "/usr/bin/open", "-a" "'path_to_external_applicaiton_which_is_100%_executable_and_works", "'my_file_here'" });
=> sometimes ok, but mostly "uhm, wtf?"..


In case 2 I have these problems:
1: external applicatin is not in the $PATH and contains a backslash {es}
2: external application is in the "/Applications/" and have spaces in the name

Please provide the actual path to the actual application, and the actual path to your actual file, exactly as you have it in your Java code that fails. In short, post actual code, not hypothetical code.


Also, is your designated application a bundled application, or is it just a plain executable? E.g. a bundled app like TextEdit.app, or a plain executable like /bin/ls. If not sure, run the 'file' command on the path to application, and post the results.

/usr/bin/open's -a option only works with bundled apps, not with plain executables. If you have a plain executable, just exec() it directly:

  exec( new String[] { "pathToExecutable", "path to arg 1" } )


Also, in #2, you have single-quotes around the name my_file_here, inside the double-quotes that represent a Java String literal. Unless your filename contains single-quotes, this is wrong: /usr/bin/ open is not a shell, and a shell is usually what interprets quoting of command-line args.



When using the same call from terminal, I have this error message:
$ /usr/bin/open -a '/User/me/tmp/blah\_blah.sh' 'file:/var/tmp/ image.jpg'
LSOpenFromURLSpec() failed with error -1081 for the file file:/var/ tmp/image.jpg.

In this command-line, you are single-quoting the path to the app, but you are also using a backslash inside the quotes. This will cause the \ to be taken literally.


It seems like you don't completely understand quoting and \-escaping rules of the shell, or are adding quotes at inappropriate places for unspecified reasons.

For example, try these command-lines in Terminal.app:
  echo '/User/me/tmp/blah\_blah.sh'
  echo "/User/me/tmp/blah\_blah.sh"
  echo /User/me/tmp/blah\_blah.sh

  echo '/User/me/tmp/blah\ blah.sh'
  echo "/User/me/tmp/blah\ blah.sh"
  echo /User/me/tmp/blah\ blah.sh

As an exercise in understanding args and quoting, write a simple Java program that prints its args to main(String[]), one per line, with the array index preceding each arg. Then run that program with the different quoted and escaped args above.


Also, you are passing a URL, not a filesystem pathname. That's probably not why this particular use of open is failing, but it's something to remember when you run applications. If the application doesn't accept URLs, then passing a URL is wrong.


  -- GG

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.