简体   繁体   English

如何使用Java更改命令提示符中的路径

[英]How to change the path in command prompt using java

import java.io.Console;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Executor;

import com.jacob.com.LibraryLoader;

import autoitx4java.AutoItX;

public class SilentInstallation {

    public static void main(String[] args) throws IOException, InterruptedException {

        String[] cmd = { "C:\\WINDOWS\\system32\\cmd.exe", "/c", "start" };
        try {
            Runtime runtime = Runtime.getRuntime();
            Process p = runtime.exec(cmd);
        }

        catch (java.io.IOException exception) {
            System.out.println("Caught IOException: " + exception.getMessage());

        }

    }
}

Here is my code in which I am running command prompt using java. 这是我在其中使用Java运行命令提示符的代码。 But the problem here I am facing is I can't be able to change the path in command prompt using java code. 但是,我面临的问题是我无法使用Java代码在命令提示符下更改路径。

Since this code is using in Automation, so is there any command or method in java that can be used to change the path in the command prompt. 由于此代码是在自动化中使用的,因此java中的任何命令或方法都可用于更改命令提示符中的路径。

I have also used ProcessBuilder to change the directory path. 我还使用过ProcessBuilder来更改目录路径。 Any Recommendations..... 任何建议.....

This should be enough: 这应该足够了:

Process p = ...
p.getOutputStream().write("cd d:\\/r/n".getBytes());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM