Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (767)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Using Spaces when executing UNIX commands?  (Read 1910 times)
0 Members and 1 Guest are viewing this topic.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Posted 2007-04-29 19:46:52 »

Hey guys –

I'm trying to execute an external program from within my Java code, which I've decided to go using Runtime.exec(). I have it working, but if there are any spaces involved at all in the application name or path to the application things just do not work.

This particular example is the Mac OS X version of the code (I have different ones for Mac, PC, and Linux), and is being shown here because it's the only platform I have tested so far.

If I want to run something called "Test.app" that is in my users folder, I would do it like this:
Runtime.getRuntime().exec("open /Users/eli/Test.app");  <---Works fine

That works perfectly, executing the app with no issue. However, if I want to execute "Test App.app" then nothing happens. The processor makes the "doing something" noise as if it is computing, but no programs open, and no error messages appear.
Runtime.getRuntime().exec("open /Users/eli/Test App.app");   <--- Does nothing
Runtime.getRuntime().exec("open /Users/eli/\"Test App.app\"");  <--- Does nothing
Runtime.getRuntime().exec("open /Users/eli/Test\\ App.app");  <--- Does nothing
Runtime.getRuntime().exec("open /Users/eli/Test*App.app");  <--- Does nothing
Runtime.getRuntime().exec("open /Users/eli/Test?App.app");  <--- Does nothing

Spaces seem to bring it down, both in directories leading to the app, and in the app's name. Is there some special way to represent spaces that I am not aware of? If not, I suppose I can have the user rename the app beforehand, but that just seems stupid. It should be noted that I have tried all of the above 5 attemps within my Terminal app (the UNIX shell for Mac OS X), and every single one works correctly, except the first of course. Surrounding it in quotes makes UNIX ignore everything within (aka the space), putting a backslash before the space means "canceling out" the character following (much like \n in Java), putting in a * allows for absolutely any character, and putting in a ? allows for anything except nothing.... so, they should all work, and do, just not when I'm doing these commands from within Java. Any ideas?

Thanks.

See my work:
OTC Software
Offline endolf

JGO Coder


Medals: 7
Exp: 15 years


Current project release date: sometime in 3003


« Reply #1 - Posted 2007-04-30 06:34:09 »

Runtime.getRuntime().exec("open \"/Users/eli/Test App.app\"");

That should do the job, but I would have expected Runtime.getRuntime().exec("open /Users/eli/Test\\ App.app"); to work too.

HTH

Endolf

Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #2 - Posted 2007-04-30 18:27:50 »

Yeah, neither worked, even though they should have. However, I was able to get it to work by passing an array of commands, in which case Java seems to ignore subsequent spaces.

Runtime.getRuntime().exec(new String[]{"open","Test App.app"},null,new File(System.getProperty("user.dir")));

The above works fine, for whatever reason. And using a File to have it start in the correct directory seems to help a lot as well.

See my work:
OTC Software
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1314 views)
2018-06-10 19:43:48

EgonOlsen (1179 views)
2018-06-10 19:43:44

EgonOlsen (916 views)
2018-06-10 19:43:20

DesertCoockie (1317 views)
2018-05-13 18:23:11

nelsongames (1106 views)
2018-04-24 18:15:36

nelsongames (1338 views)
2018-04-24 18:14:32

ivj94 (2080 views)
2018-03-24 14:47:39

ivj94 (1231 views)
2018-03-24 14:46:31

ivj94 (2230 views)
2018-03-24 14:43:53

Solater (798 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!