private static void unTarUsingTar(File inFile, File untarDir, boolean gzipped) throws IOException { StringBuffer untarCommand = new StringBuffer(); if (gzipped) { untarCommand.append(" gzip -dc '"); untarCommand.append(FileUtil.makeSecureShellPath(inFile)); untarCommand.append("' | ("); } untarCommand.append("cd '"); untarCommand.append(FileUtil.makeSecureShellPath(untarDir)); untarCommand.append("' && "); untarCommand.append("tar -xf "); if (gzipped) { untarCommand.append(" -)"); } else { untarCommand.append(FileUtil.makeSecureShellPath(inFile)); } String[] shellCmd = { "bash", "-c", untarCommand.toString() }; ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd); shexec.execute(); int exitcode = shexec.getExitCode(); if (exitcode != 0) { throw new IOException("Error untarring file " + inFile + ". Tar process exited with exit code " + exitcode); } }
if (LOG.isDebugEnabled()) { LOG.debug("setsid exited with exit code " + (shexec != null ? shexec.getExitCode() : "(null executor)"));
/** * Change the permissions on a file / directory, recursively, if * needed. * @param filename name of the file whose permissions are to change * @param perm permission string * @param recursive true, if permissions should be changed recursively * @return the exit code from the command. * @throws IOException */ public static int chmod(String filename, String perm, boolean recursive) throws IOException { String [] cmd = Shell.getSetPermissionCommand(perm, recursive); String[] args = new String[cmd.length + 1]; System.arraycopy(cmd, 0, args, 0, cmd.length); args[cmd.length] = new File(filename).getPath(); ShellCommandExecutor shExec = new ShellCommandExecutor(args); try { shExec.execute(); }catch(IOException e) { if(LOG.isDebugEnabled()) { LOG.debug("Error while changing permission : " + filename +" Exception: " + StringUtils.stringifyException(e)); } } return shExec.getExitCode(); }
private static boolean isSetsidSupported() { if (Shell.WINDOWS) { return false; } ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.debug("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code if (LOG.isDebugEnabled()) { LOG.debug("setsid exited with exit code " + (shexec != null ? shexec.getExitCode() : "(null executor)")); } } return setsidSupported; }
/** * Sends terminate signal to all the process belonging to the passed process * group, allowing the group to gracefully exit. * * @param pgrpId process group id */ public static void terminateProcessGroup(String pgrpId) { ShellCommandExecutor shexec = null; try { String[] args = { "kill", "--", "-" + pgrpId }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("Error executing shell command " + ioe); } finally { LOG.info("Killing all processes in the process group " + pgrpId + " with SIGTERM. Exit code " + shexec.getExitCode()); } }
public String getMajorAndMinorNumber(String devName) { String output = null; Shell.ShellCommandExecutor shexec = new Shell.ShellCommandExecutor( new String[]{"stat", "-c", "%t:%T", "/dev/" + devName}); try { LOG.debug("Get FPGA major-minor numbers from /dev/" + devName); shexec.execute(); String[] strs = shexec.getOutput().trim().split(":"); LOG.debug("stat output:" + shexec.getOutput()); output = Integer.parseInt(strs[0], 16) + ":" + Integer.parseInt(strs[1], 16); } catch (IOException e) { String msg = "Failed to get major-minor number from reading /dev/" + devName; LOG.warn(msg); LOG.debug("Command output:" + shexec.getOutput() + ", exit code:" + shexec.getExitCode()); } return output; }
/** * Runs the script given in args * @param args script name followed by its argumnets * @param dir current working directory. * @throws IOException */ public void runScript(List<String> args, File dir) throws IOException { ShellCommandExecutor shexec = new ShellCommandExecutor(args.toArray(new String[0]), dir); shexec.execute(); int exitCode = shexec.getExitCode(); if (exitCode != 0) { throw new IOException("Task debug script exit with nonzero status of " + exitCode + "."); } }
/** * Runs the script given in args * @param args script name followed by its argumnets * @param dir current working directory. * @throws IOException */ public void runScript(List<String> args, File dir) throws IOException { ShellCommandExecutor shexec = new ShellCommandExecutor(args.toArray(new String[0]), dir); shexec.execute(); int exitCode = shexec.getExitCode(); if (exitCode != 0) { throw new IOException("Task debug script exit with nonzero status of " + exitCode + "."); } }
private static boolean isSetsidSupported() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
private static boolean isSetsidSupported() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); return setsidSupported; } }
private static boolean isSetsidSupported() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
private static boolean isSetsidSupported() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
private static boolean isSetsidSupported() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
protected static boolean isSetsidAvailable() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = { "setsid", "bash", "-c", "echo $$" }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
private static boolean isSetsidSupported() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = {"setsid", "bash", "-c", "echo $$"}; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
protected static boolean isSetsidAvailable() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = { "setsid", "bash", "-c", "echo $$" }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
protected static boolean isSetsidAvailable() { ShellCommandExecutor shexec = null; boolean setsidSupported = true; try { String[] args = { "setsid", "bash", "-c", "echo $$" }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (IOException ioe) { LOG.warn("setsid is not available on this machine. So not using it."); setsidSupported = false; } finally { // handle the exit code LOG.info("setsid exited with exit code " + shexec.getExitCode()); } return setsidSupported; }
@Override void runDebugScript(DebugScriptContext context) throws IOException { List<String> wrappedCommand = TaskLog.captureDebugOut(context.args, context.stdout); // run the script. ShellCommandExecutor shexec = new ShellCommandExecutor(wrappedCommand.toArray(new String[0]), context.workDir); shexec.execute(); int exitCode = shexec.getExitCode(); if (exitCode != 0) { throw new IOException("Task debug script exit with nonzero status of " + exitCode + "."); } }
return shExec.getExitCode();
in = new BufferedReader(new StringReader(shexec.getOutput())); inpMsg = in.readLine(); exitValue = shexec.getExitCode(); if (inpMsg == null || exitValue != 0) { throw createIOException(fileName, inpMsg, errMsg, exitValue, null);