0

I tried to execute a multiple commands in a single command line prompt. Here i need to hide to directories. I used this command "C:\Windows\System32>cacls C:\Users\FSSD\Desktop\test1 /e /c /d %username% & cacls C:\Users\FSSD\Desktop\test3 /e /c /d %username% & cacls C:\Users\FSSD\Desktop\test3 /e /c /d %username%)"in commad prompt it executed well, when i use this code in my java Program it doesn't work completely. The first command will be executed.

In my java code i used this command like this,

Runtime runtime = Runtime.getRuntime();
    try {
        Process process = runtime
                .exec("cmd.exe /c start cacls C:/Users/FSSD/Desktop/test1  /e /c /d %username%) " + "&"+            
                      "  cacls C:/Users/FSSD/Desktop/test2  /e /c /d %username%" +"&"+  
                      "  cacls C:/Users/FSSD/Desktop/test3  /e /c /d %username%");

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

in this what mistake i done, else any other possible to achieve this..

3
  • could you post the exception/stacktrace you are getting while you are executing this ? Commented Sep 12, 2011 at 9:59
  • there is no exception message in my console, the first cmd (cmd.exe /c start cacls C:/Users/FSSD/Desktop/test1 /e /c /d %username%))only execute Commented Sep 12, 2011 at 10:26
  • I don't see the way it's related to Java. Create 1.cmd and paste your command line there, check if it works at all. If it does, there's something with your Java, if it doesn't (most probably), it's not a Java-related issue. Commented Sep 12, 2011 at 10:28

2 Answers 2

1

Why don't you put that lengthy command into a .bat or .cmd file and invoke that file from Java?

Sign up to request clarification or add additional context in comments.

Comments

1
.exec("cmd.exe /c start cacls C:/Users/FSSD/Desktop/test1  /e /c /d %username%) " + "&"+
______________________________________________________________________________^

what is it for? (%username%))

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.