0

cmdFile.sh:

cd "E:\\myWorkSpace\\sampleTest"
mkdir "E:\\myWorkSpace\\sampleTest\output"

Java:

runtime.exec("cmdFile.sh");

The above shell script creates the folder if executed through a command prompt. But, if it is executed using Java, then the folder is not created.

3
  • Here you have an example how to run external programm with reading error and outputstream, so you can see if you get an error while running ` cmdFile.sh` Commented Jun 30, 2014 at 6:07
  • @sri: What error do you get from Java? Commented Jun 30, 2014 at 6:14
  • 1
    These are windows file paths, not Mac OS Commented Jun 30, 2014 at 6:31

1 Answer 1

2

runtime.exec actually executes a process. Did you mark cmdFile.sh as an executable? Otherwise you should run the following in your terminal first:

chmod +x cmdFile.sh

Otherwise you should call a shell with cmdFile.sh as argument, for instance:

runtime.exec("/bin/bash cmdFile.sh");

On a sidenote, you can write te script in Java as well (so you don't need to start an additional process):

File f = new File("E:\\myWorkSpace\\sampleTest\\output");
boolean wasSuccessfull = f.mkdir(); //or mkdirs if there are more possible nonexisting parent-folders.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.