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
  • 8,562
  • 19
  • 63
  • 82
  • 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,427
  • 7
  • 44
  • 93
Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
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,511
  • 28
  • 39
  • 51