0

I have a code like this:

String[] cmd = { "osascript","mylocation" };
Process process = Runtime.getRuntime().exec(cmd);
process.waitFor();

The location myLocation file is inside my script folder. This class is in src folder. I tried ../script/file which is not working.

How can I call the file in script folder?

sriram
  • 7,990
  • 19
  • 58
  • 80
  • Are you looking for this? http://stackoverflow.com/questions/4871051/getting-the-current-working-directory-in-java – Kon Dec 24 '13 at 04:47

2 Answers2

0

From the Javadoc for Runtime

    public Process exec(String[] cmdarray,
           String[] envp,
           File dir)
             throws IOException

Executes the specified command and arguments in a separate process with the specified environment and working directory.

eatSleepCode
  • 4,201
  • 6
  • 39
  • 84
Dawood ibn Kareem
  • 73,541
  • 13
  • 95
  • 104
0

You need to do provide the relative path as given below:

    String[] cmd = { "..\\script\\osascript", "mylocation" };
    Process process = Runtime.getRuntime().exec(cmd);
    process.waitFor();
Infinite Recursion
  • 6,445
  • 28
  • 38
  • 51