0

The answer which the other use shown and marked as duplicate still doesn't work.

Instead of marking it duplicate and refusing the question it would be better to answer it and make sure that the asker of the question that is me is satisfied with the answer.

I want to run a Batch file whose name is Test.bat and which is present in the same directory where this java file would be executed and the directory string is stored in dir but I have tried the following code to call it but it is not working.

Please someone help me with this.

public static void main(String[] args)  {
    String dir = System.getProperty("user.dir");   
    dir = dir.replace('\\','/');

    System.out.println("current dir = " + dir);

    ProcessBuilder batch = new ProcessBuilder("Test.bat");
    try {
        batch.start();
        } 
    catch (IOException e) 
        {
        e.printStackTrace();
        }
    }
Abhi
  • 1,080
  • 1
  • 7
  • 21
  • You are not using the dir value. should you be passing `ProcessBuilder batch = new ProcessBuilder(dir+"/Test.bat");` – Jerin Joseph May 12 '17 at 16:15
  • 1
    You may want to read [Executing a Command](http://exampledepot.8waytrips.com/egs/java.lang/Exec.html), [Reading Output from a Command](http://exampledepot.8waytrips.com/egs/java.lang/ReadFromCommand.html), [Sending Input to a Command](http://exampledepot.8waytrips.com/egs/java.lang/WriteToCommand.html) – Edwin Dalorzo May 12 '17 at 16:18
  • @EdwinDalorzo I don't think the question you marked as duplicate answers this question. The answer here is that he needs to call `ProcessBuilder.inheritIO()`. I don't see that answer in the linked duplicate that you suggested. – Klitos Kyriacou May 12 '17 at 16:52
  • @KlitosKyriacou I changed the answer for another one that seems more appropriate. – Edwin Dalorzo May 12 '17 at 16:56
  • 1
    @EdwinDalorzo I have already told I have tried all the answers and the answer which you have suggested doesn't work – Abhi May 14 '17 at 04:51
  • 1
    @JerinJoseph I have tried your answer but still It did not work :( – Abhi May 14 '17 at 04:56

0 Answers0