If I need to start the program from the console, which is located in a folder with a name of two parts (with a space in the name), then I do it like this:

$ open /"My project"/myprogram.app 

that is, this folder must be quoted. But how now to make it from the Java program? If you try this:

 Runtime.getRuntime().exec("open /\"Meine Projekt\"/myprogram.app"); 

then nothing happens - myprogram.app does not start. And here is the code:

 Runtime.getRuntime().exec("open /Projekt/myprogram.app"); 

will work.

  • one
    enter \ " - carapuz
  • Then there is no result - myprogram.app did not load. - Adam
  • Try this: Runtime.getRuntime (). exec ("open / Meine \ Projekt / myprogram.app"); - carapuz
  • Here the error is at the level of compilation - the string is incorrectly composed. - Adam

2 answers 2

Try this:

 Runtime.getRuntime().exec( new String[] { "open", "/Meine Projekt/myprogram.app" } ); 

With parameters:

 Runtime.getRuntime().exec( new String[] { "open", "/Meine Projekt/myprogram.app", "--args", "param" } ); 
  • Does not work. - Adam
  • On JavaRanch write need to remove all quotes. I updated, try. - Gleb Kuznetsov
  • It worked. But now I'm trying to start with the parameters: Runtime.getRuntime().exec( new String[] { "open", "/Meine Projekt/myprogram.app --args param" } ); and again no reaction. - Adam

You need to specify a transition to this folder, where the program is running from ... For this, for example, you need to build bat-file in Windows

 cd <имя ΠΏΠ°ΠΏΠΊΠΈ, Π³Π΄Π΅ находится запускаСмая ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ°> patch = %PATCH%; <ΡƒΠΊΠ°Π·Π°Ρ‚ΡŒ всС Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΡ‹Π΅ ΠΏΡƒΡ‚ΠΈ для выполнСния ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΡ‹> <ΠΏΡƒΡ‚ΡŒ ΠΊ запускаСмой Π½Π° Π²Ρ‹ΠΏΠΎΠ»Π½Π΅Π½ΠΈΠ΅ ΠΏΡ€Π³Ρ€Π°ΠΌΠΌΡ‹> 

Then

 Runtime.getRuntime().exec...<"имя Bat-file> 

In UNIX, it is similar to build a script file.