final String[] args) throws ExecutionException {
final String commandexecutable;
final String[] commandargs;
if (!command && null == scriptfile) {
throw new ExecutionException("Could not determine the command to dispatch");
}
if ("windows".equals(nodeentry.getOsFamily())) {
//TODO: escape args properly for windows
commandexecutable = "cmd.exe";
if (command) {
ArrayList<String> list = new ArrayList<String>();
list.add(0, "/c");
list.addAll(Arrays.asList(args));
commandargs = list.toArray(new String[list.size()]);
} else if (null != scriptfile) {
//commandString is the script file location
ArrayList<String> list = new ArrayList<String>();
list.add(scriptfile.getAbsolutePath());
if(args!=null && args.length>0){
list.addAll(Arrays.asList(args));
}
list.add(0,"/c");
commandargs = list.toArray(new String[list.size()]);
} else {
throw new ExecutionException("Could not determine the command to dispatch");
}
} else {
if (command) {
commandexecutable = "/bin/sh";
commandargs = new String[]{"-c", StringUtils.join(args, " ")};
} else if (null != scriptfile) {
final String scriptPath = scriptfile.getAbsolutePath();
commandexecutable = scriptPath;
commandargs=args;
} else {
throw new ExecutionException("Could not determine the command to dispatch");
}
}
return new ExecTaskParameters() {
public String getCommandexecutable() {
return commandexecutable;