0

I am trying to install postgreSql.exe through java code. I have kept installer exe file under workspace/project-root-folder/data. I am trying to execute below command through my java code:

installationCommand = "postgresql-9.5.3-1-windows-x64.exe --mode unattended --installer-language en --serverport 5433 --superaccount test_admin --superpassword  ‘password’"

Below is the code snippet which I am using in my java code :

System.out.println("Lets install postgreSql");
ProcessBuilder b = new ProcessBuilder();
b.directory(new File("data").getAbsoluteFile());
b.command(installationCommand);
b.start();

With this set up I am getting below exception:

   java.io.IOException: Cannot run program "postgresql-9.5.3-1-windows-x64.exe --mode unattended --installer-language en --serverport 5433 --superaccount protoel_admin --superpassword  ‘password’" (in directory "C:\DurgeshProjectWork\Workspace\protoel-core\data"): CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at frontend.guifx.pginstallation.PgStandaloneInstaller.installPg(PgStandaloneInstaller.java:27)
    at frontend.guifx.controller.ProtoelController.initialize(ProtoelController.java:386)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2552)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2445)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3218)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3179)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3152)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3128)
    at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3108)
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3101)
    at frontend.guifx.main.ProToelApplication.start(ProToelApplication.java:34)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$159(LauncherImpl.java:863)
    at com.sun.javafx.application.LauncherImpl$$Lambda$53/953109155.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$172(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl$$Lambda$45/2034688500.run(Unknown Source)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
    at com.sun.javafx.application.PlatformImpl$$Lambda$48/3243045.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
    at com.sun.javafx.application.PlatformImpl$$Lambda$47/1007251739.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$145(WinApplication.java:101)
    at com.sun.glass.ui.win.WinApplication$$Lambda$36/1508395126.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 25 more

Could anybody please let me know how to execute the command from specific directory through java code. Kindly help in this. Thanks in advance

0

2 Answers 2

1

It seems that you're specifying wrong directory in .directory() method. You have to double check that. Make sure that the value passed to this method points to the postgresql installer directory.

Sign up to request clarification or add additional context in comments.

1 Comment

the value in directory function is coming as expected. it is showing the directory till my data folder. But still throwing the exception above
0

To use this command, you have to split every argument into an array of Strings. See ProcessBuilder.command(String... args) documentation. You could use installationCommand.split(" ") to get an String[].

Also check if the directory path is correctly, just in case.

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.