0

When I run this program itdisplays the following text instead of the dir dump why? This is what it displays.

Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

It should also display the dir out put but it does now why?

The code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class ExecuteWindowsCommandThread implements Runnable {

    public ExecuteWindowsCommandThread(String command) {
    }

    @Override
    public void run() {
        try {
            final Process p = Runtime.getRuntime().exec("cmd c/ dir");
            //p.waitFor();
            BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;

            while ((line = input.readLine()) != null) {
                System.out.println(line);
            }
            System.out.println("Done2");

        }

        catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("Done");
    }
}
0

1 Answer 1

2

Don't use c/ instead use /c so, Change:

final Process p = Runtime.getRuntime().exec("cmd c/ dir");

to:

final Process p = Runtime.getRuntime().exec("cmd /c dir");

and it will work.

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.