Pregunta

My setup is as follows: C: contains operating system and final release of programs Z: contains code I am working on

  • I am using Netbeans, which is installed on C:\Program Files (x86)
  • My project folders are in Z:
  • I am trying to debug a project which needs to run a process where the file for the process directory is "C:\TaxiPIM"

I have tried:

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "Pim_Update_Client.jar");
pb.directory(new File("/TaxiPIM"));

and:

ProcessBuilder pb = new ProcessBuilder("java", "-jar", "Pim_Update_Client.jar");
pb.directory(new File("c:/TaxiPIM"));

and ended up google-e-eyed with results explaining how to change the directory...

But I need to change the drive as well as the directory.

Thanks for reading - feedback is most appreciated!

¿Fue útil?

Solución

Edit: ProcessBuilders directory(File) method returns a new ProcessBuilder so try pb=pb.directory(new File("...)

crude way would be to export the command to a batchfikle in the same dir as your project and putting the change drive code into the batch file, too and then run the batch file from your code.

Example that changes from a directory on C to a directory on D; (i have my NetBeans installation and the project-directory on the C-Drive)

ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c","start","cmd");
pb=pb.directory(new File("D:\\src"));
pb.start();

Otros consejos

And then after getting the new ProcessBuilder, just put in your command:

ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c","start","cmd");
pb = pb.directory(new File("c:/TaxiPIM/"));
pb.command("java", "-jar", "Pim_Update_Client.jar");

Thanks again to @masterX244

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top