/** * Gets the output of the given (console based) commandline * * @param aCommandLine to execute * @param dir the working directory for the execution * @return the result of the command */ public static String getExecOutput(String[] aCommandLine, String dir) { return getExecOutput(aCommandLine, dir, false); }
/** * Gets the output of the given (console based) commandline * * @param aCommandLine to execute * @return the result of the command */ public static String getExecOutput(String[] aCommandLine) { return getExecOutput(aCommandLine, null, false); }
/** * Gets the output of the given (console based) commandline * * @param aCommandLine to execute * @param forceToGetStdOut if true returns stdout * @return the result of the command */ public static String getExecOutput(String[] aCommandLine, boolean forceToGetStdOut) { return getExecOutput(aCommandLine, null, forceToGetStdOut); }
/** * Gets the absolute Pathe to the given custom command. This is necessary, because the command * may be located at /bin on linux but in /usr/bin on Sun Solaris. Which can locate it in your * $PATH for you. * * @param aCommand a Custom Command * @return /bin/aCommand on linux /usr/bin/aCommand on solaris */ public static String getCustomCommand(String aCommand) { return FileExecutor.getExecOutput(new String[]{whichCommand, aCommand}).trim(); }
/** * Gets the absolute Pathe to the rm (Remove) Command. This is necessary, because the command is * located at /bin on linux but in /usr/bin on Sun Solaris. * * @return /bin/rm on linux /usr/bin/rm on solaris */ public static String getRmCommand() { return FileExecutor.getExecOutput(new String[]{whichCommand, "rm"}).trim(); }
/** * Gets the absolute Pathe to the ypcat (YellowPage/NIS Cat) Command. This is necessary, because * the command is located at /bin on linux but in /usr/bin on Sun Solaris. * * @return /bin/ypcat on linux /usr/bin/ypcat on solaris */ public static String getYpCatCommand() { return FileExecutor.getExecOutput(new String[]{whichCommand, "ypcat"}).trim(); }
/** * Executes this ShellScript with the given Params.<br> * NOTE: the params cannot be contain whitespaces.<br> * This (su -c <br>"cp from to"</br>) would not work:<br> * because the underlaying java.runtime.exec("command") does not handle balanced or unbalanced * (") correctly.<br> * else just whitespace separate tokens.<br> * This means for the sample. runtime.exec() would ever execute such as: su "-c" "\"cp" * "fromFile" "toFile\""<br> * But this his hidden in Sun's native code ;-(<br> * This was the reason to write this class to have a Workaround :-) * * @param itsParams * @return the output from stdout of the execution. */ public String exec(String itsParams) { FileExecutor.getExecOutput(new String[]{UnixHelper.getCustomCommand("chmod"), "+x", itsLocation}); if (itsParams != null) { return FileExecutor.getExecOutput(new String[]{itsLocation, itsParams}); } else { return FileExecutor.getExecOutput(new String[]{itsLocation}); } }
/** * Gets the absolute path of the cp (Copy) command. This is necessary, because the command is * located at /bin on linux but in /usr/bin on Sun Solaris. * * @return /bin/cp on linux /usr/bin/cp on solaris */ public static String getCpCommand() { return FileExecutor.getExecOutput(new String[]{getWhichCommand(), "cp"}).trim(); }
/** * Gets the absolute path to the su (SuperUser) command. This is necessary, because the command * is located at /bin on linux but in /usr/bin on Sun Solaris. * * @return /bin/su on linux /usr/bin/su on solaris */ public static String getSuCommand() { return FileExecutor.getExecOutput(new String[]{getWhichCommand(), "su"}).trim(); }
/** * Gets the Name of the XDG-Desktop Folder if defined in the $HOME/.config/user-dirs.dirs File as absolute File/Pathname * * @return The absolute File/Pathname of the Desktop foldername. */ public String getXdgDesktopfolder() { File configFile = new File(getHome() + File.separator + ".config" + File.separator + "user-dirs.dirs"); if (configFile.exists()) { if (XDGDesktopFolderNameScript == null) /** TODO: can be optimized with a shared script **/ { XDGDesktopFolderNameScriptFilename = getCreatedXDGDesktopFolderNameScriptFilename(); } FileExecutor.getExecOutput(new String[]{UnixHelper.getCustomCommand("chmod"), "+x", XDGDesktopFolderNameScriptFilename}, true); String xdgDesktopfolder = FileExecutor.getExecOutput(new String[]{XDGDesktopFolderNameScriptFilename}, true).trim(); new File(XDGDesktopFolderNameScriptFilename).delete(); return xdgDesktopfolder; } else { return getHome() + File.separator + "Desktop"; } }
.getExecOutput(new String[]{ypcommand, "passwd"}))); while ((line = reader.readLine()) != null)
/** * Returns value of the {@code SUDO_USER} enviroment variable. The variable * is set when the installer is executed using {@code sudo} command. * @return value of {@code SUDO_USER} */ private UnixUser getSudoUser() { String printEnvCmd = UnixHelper.getCustomCommand("printenv"); String sudoUserName = FileExecutor.getExecOutput( new String[]{printEnvCmd, "SUDO_USER"}, true).trim(); for (UnixUser user : getUsers()) { if (user.getName().equals(sudoUserName)) { return user; } } return null; }
/** * Creates Extended Locale Enabled XdgDesktopIcon Command script. * Fills the File myXdgDesktopIconScript with the content of * com/izforge/izpack/util/os/unix/xdgscript.sh and uses this to * creates User Desktop icons * * @param shortCutLocation in which folder should this stored. * @throws ResourceNotFoundException resource not found error */ private void createExtXdgDesktopIconCmd(File shortCutLocation) throws ResourceNotFoundException { ShellScript myXdgDesktopIconScript = new ShellScript(null); String lines = resources.getString("/com/izforge/izpack/util/unix/xdgdesktopiconscript.sh", null); myXdgDesktopIconScript.append(lines); myXdgDesktopIconCmd = shortCutLocation + FS + "IzPackLocaleEnabledXdgDesktopIconScript.sh"; myXdgDesktopIconScript.write(myXdgDesktopIconCmd); FileExecutor.getExecOutput(new String[]{UnixHelper.getCustomCommand("chmod"), "+x", myXdgDesktopIconCmd}, true); }
FileExecutor.getExecOutput(new String[]{chmodCmd, "u+x", StringTool.escapeSpaces(myDesktopFile.getPath())}); FileExecutor.getExecOutput(new String[]{chownCmd, sudoUser.getName(), StringTool.escapeSpaces(myDesktopFile.getPath())});
FileExecutor.getExecOutput(new String[]{chmod, "uga+rwx", tempFile.toString()});