Make setting of working directory to user-home optional for shell interpreter

This commit is contained in:
Prabhjyot Singh 2017-09-05 14:15:03 +05:30
parent d6203c51ed
commit 9164ed2c0f
2 changed files with 12 additions and 1 deletions

View file

@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory;
public class ShellInterpreter extends KerberosInterpreter {
private static final Logger LOGGER = LoggerFactory.getLogger(ShellInterpreter.class);
private static final String TIMEOUT_PROPERTY = "shell.command.timeout.millisecs";
private static final String DIRECTORY_USER_HOME = "shell.working.directory.user.home";
private final boolean isWindows = System.getProperty("os.name").startsWith("Windows");
private final String shell = isWindows ? "cmd /c" : "bash -c";
ConcurrentHashMap<String, DefaultExecutor> executors;
@ -99,7 +100,10 @@ public class ShellInterpreter extends KerberosInterpreter {
contextInterpreter.out, contextInterpreter.out));
executor.setWatchdog(new ExecuteWatchdog(Long.valueOf(getProperty(TIMEOUT_PROPERTY))));
executors.put(contextInterpreter.getParagraphId(), executor);
executor.setWorkingDirectory(new File(System.getProperty("user.home")));
if (Boolean.valueOf(getProperty(DIRECTORY_USER_HOME))) {
executor.setWorkingDirectory(new File(System.getProperty("user.home")));
}
int exitVal = executor.execute(cmdLine);
LOGGER.info("Paragraph " + contextInterpreter.getParagraphId()
+ " return with exit value: " + exitVal);

View file

@ -31,6 +31,13 @@
"defaultValue": "",
"description": "Kerberos principal",
"type": "string"
},
"shell.working.directory.user.home": {
"envName": "SHELL_WORKING_DIRECTORY_USER_HOME",
"propertyName": "shell.working.directory.user.home",
"defaultValue": false,
"description": "If this set to true, the shell's working directory will be set to user home",
"type": "checkbox"
}
},
"editor": {