3

Hi I want to execute this command from java code :

cd C:/Users/Amira/junoWorkspace/TestProjectUI
mvn -Dtest=MyClassTest.java test

So I found this method but i didn't find a way to adapt it to my case :

    public static void main(String[] args) throws IOException
    {
            try
            {
                    // Runtime runtime = Runtime.getRuntime();
                   String[] cmd={"C:\\WINDOWS\\System32\\cmd.exe","/C start test.bat"};
                    Process p = Runtime.getRuntime().exec(cmd);
            // TODO code application logic here
            }
            catch(IOException e)
            {
                System.err.println("echec de l'execution du script: "+e);
                System.exit(1);
            }
    }

Any idea ? Cheers

4

1 回答 1

4

您正在寻找的是ProcessBuilder允许您设置工作目录等参数,它还允许多个参数,请查看此处此处以及ProcessBuilder Demo以获取有关如何使用它的一些示例

于 2012-07-08T20:31:24.587 回答