-3
String run="c:\\Program Files\DOSBox-0.74\dosbox.exe dosbox -c mount c c:\games";

这个词c c:\games被删除。

请告诉我如何防止这种情况?我应该使用文字在命令中插入空格吗?

4

1 回答 1

0

一点实验...

public class Test {

    public static void main(String[] args) {
        try {
            ProcessBuilder pb = new ProcessBuilder("C:\\Program Files (x86)\\DOSBox-0.74\\DOSBox.exe", "dosbox", "-c", "mount c c:\\games");
            pb.redirectError();
            Process p = pb.start();
            new Thread(new InputStreamConsumer(p.getInputStream())).start();
            System.out.println("Have exited with " + p.waitFor());
        } catch (IOException | InterruptedException exp) {
            exp.printStackTrace();
        }
    }

    public static class InputStreamConsumer implements Runnable {

        private InputStream is;

        public InputStreamConsumer(InputStream inputStream) {
            is = inputStream;
        }

        @Override
        public void run() {
            int in = -1;
            try {
                while ((in = is.read()) != -1) {
                    System.out.print((char) in);
                }
            } catch (IOException exp) {
                exp.printStackTrace();
            }
        }

    }

}
于 2014-08-12T05:11:29.947 回答