Skip to Main Content

Global ProcessBuilder?

user2018218Apr 16 2018 — edited Apr 16 2018

Hey guys,

Hopefully this is not a dumb question, but here it goes.

I have a program that I will pass from OS to OS. Most of the commands usually are the same, but there are some factors that need to change depending on which OS you are on.

opening up a windows cmd prompt, as opposed to opening up a shell command prompt.

So for example the code below.

[code]

if(os1.equals("Linux")){

cmdln = cmdln;

ProcessBuilder builder = new ProcessBuilder(cmdln, c_nix, " cd " + cdtodir + " && " + entercmd + " && " + secdump1);

try {

@SuppressWarnings("unused")

Process pr = builder.start();

} catch (IOException e) {

e.printStackTrace();

}

} else if (os1.equals("Windows")) {

cmdln = cmdln_win;

ProcessBuilder builder = new ProcessBuilder(cmdln, c_win, "cd " + cdtodir + " && " + entercmd + " && " + secdump1);

try {

@SuppressWarnings("unused")

Process pr = builder.start();

} catch (IOException e) {

e.printStackTrace();

}

}

[/code]

So I created some variable to throw into the process builder.

I am not sure if it would be easier to do it this way - just do an if else, etc...

Or is there a way to pass around a global ProcessBuilder where you could do something like.

[code]

if(os1.equals("Linux")){

cmdln = cmdln_nix;

secdump1 = <unix command>

} else if (os1.equals("Windows")) {

cmdln = cmdln_win;

secdump1 = <windows command>

}

ProcessBuilder builder = new ProcessBuilder(cmdln, c_win, "cd " + cdtodir + " && " + entercmd + " && " + secdump1);

try {

@SuppressWarnings("unused")

Process pr = builder.start();

} catch (IOException e) {

e.printStackTrace();

}

[/code]

just looking for opinions on what would be the best way to go about doing this.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked due to inactivity on May 14 2018
Added on Apr 16 2018
1 comment
134 views