📄 sysutils.java
字号:
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(162), "A signal is already pending.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(164), "No more threads can be created in the system.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(167), "Unable to lock a region of a file.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(170), "The requested resource is in use.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(173), "A lock request was not outstanding for the supplied cancel region.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(174), "The file system does not support atomic changes to the lock type.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(180), "The system detected a segment number that was not correct.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(182), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(183), "Cannot create a file when that file already exists.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(186), "The flag passed is not correct.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(187), "The specified system semaphore name was not found.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(188), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(189), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(190), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(191), "Cannot run %1 in Win32 mode.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(192), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(193), "%1 is not a valid Win32 application.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(194), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(195), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(196), "The operating system cannot run this application program.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(197),
"The operating system is not presently configured to run this application.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(198), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(199), "The operating system cannot run this application program.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(200), "The code segment cannot be greater than or equal to 64K.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(201), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(202), "The operating system cannot run %1.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(203), "The system could not find the environment option that was entered.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(205), "No process in the command subtree has a signal handler.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(206), "The filename or extension is too long.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(207), "The ring 2 stack is in use.");
WINDOWS_SYSTEM_ERROR_CODES
.put(new Integer(208),
"The global filename characters, * or ?, are entered incorrectly or too many global filename characters are specified.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(209), "The signal being posted is not correct.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(210), "The signal handler cannot be set.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(212), "The segment is locked and cannot be reallocated.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(214),
"Too many dynamic-link modules are attached to this program or dynamic-link module.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(215), "Cannot nest calls to LoadModule.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(216),
"The image file %1 is valid, but is for a machine type other than the current machine.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(217), "The image file %1 is signed, unable to modify.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(218), "The image file %1 is strong signed, unable to modify.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(230), "The pipe state is invalid.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(231), "All pipe instances are busy.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(232), "The pipe is being closed.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(233), "No process is on the other end of the pipe.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(234), "More data is available.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(240), "The session was canceled.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(254), "The specified extended attribute name was invalid.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(255), "The extended attributes are inconsistent.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(258), "The wait operation timed out.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(259), "No more data is available.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(266), "The copy functions cannot be used.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(267), "The directory name is invalid.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(275), "The extended attributes did not fit in the buffer.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(276), "The extended attribute file on the mounted file system is corrupt.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(277), "The extended attribute table file is full.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(278), "The specified extended attribute handle is invalid.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(282), "The mounted file system does not support extended attributes.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(288), "Attempt to release mutex not owned by caller.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(298), "Too many posts were made to a semaphore.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(299),
"Only part of a ReadProcessMemory or WriteProcessMemory request was completed.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(300), "The oplock request is denied.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(301), "An invalid oplock acknowledgment was received by the system.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(302), "The volume is too fragmented to complete this operation.");
WINDOWS_SYSTEM_ERROR_CODES
.put(new Integer(303), "The file cannot be opened because it is in the process of being deleted.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(317),
"The system cannot find message text for message number 0x%1 in the message file for %2.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(318), "The scope specified was not found.");
WINDOWS_SYSTEM_ERROR_CODES.put(new Integer(487), "Attempt to access invalid address.");
}
public static String getErrorTextById(final int id) {
String os = System.getProperty("os.name");
if (os.indexOf("Windows") >= 0) {
return (String) WINDOWS_SYSTEM_ERROR_CODES.get(new Integer(id));
}
return "";
}
/**
* Picks a random number between 0 and (below) the givenNumber.
*
* @param number the givenNumber
*
* @return a number n: 0 <= n < givenNumber
*/
public static boolean canExecute(final String cmd) {
Process proc = null;
log.debug("Can we Execute cmd: " + cmd);
try {
proc = Runtime.getRuntime().exec(cmd);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
proc.waitFor();
log.debug("Exit value: " + proc.exitValue());
log.error("Exit value: " + SysUtils.getErrorTextById(proc.exitValue()));
return proc.exitValue() == 0;
}
catch (Exception e) {
log.error("Can't execute: " + cmd, e);
if (proc != null) {
log.error(" --> Can't execute: '" + cmd + "'. Exit value: " + proc.exitValue());
log.error(" --> Can't execute: '" + cmd + "'. " + SysUtils.getErrorTextById(proc.exitValue()));
}
}
return false;
}
/**
* Execute a system program on a file in a certain directory.
*
* @param unArchiveCommand the command to run, including possible options
* @param sourceFile the file
* @param unPackDestinationDirectory the directory
* @return true on succes, false otherwise
*/
public static boolean execute(final String unArchiveCommand, File sourceFile, File unPackDestinationDirectory) {
Process proc = null;
String[] cmd = null;
StringBuffer cmd4Log = new StringBuffer();
log.debug("unArchiveCommand: " + unArchiveCommand);
// prepare the command by first creating a command array, containing the program, options and source file
// first parse the command from config
String[] tmpCmd = unArchiveCommand.split(" ");
try {
// and then copy the thing into a new larger array
cmd = new String[tmpCmd.length + 1];
for (int i = 0; i < tmpCmd.length; i++) {
cmd[i] = tmpCmd[i];
// for logging, never mind the overhead
cmd4Log.append(cmd[i] + " ");
}
// cmd[tmpCmd.length] = "\"" + sourceFile.getAbsolutePath() + "\"";
cmd[tmpCmd.length] = sourceFile.getAbsolutePath();
cmd4Log.append(cmd[tmpCmd.length]);
log.debug("Executing: '" + cmd4Log + "' from working directory '" + unPackDestinationDirectory + "'");
// run the command in the target directory (unPackDestinationDirectory) on the archive (sourceFile)
// TODO: I pass cmd4Log instead of cmd[], since hh.exe does not do well...
proc = Runtime.getRuntime().exec(cmd4Log.toString(), null, unPackDestinationDirectory);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
proc.waitFor();
log.debug("Exit value: " + SysUtils.getErrorTextById(proc.exitValue()));
// everthing OK?
if (proc.exitValue() == 0) {
// got it right first time
log.debug("Succesfully executed: '" + cmd4Log + "'.");
return true;
} else {
// error executing proc
log.debug("Retrying, couldn't execute: '" + cmd4Log + "'. Exit value: "
+ SysUtils.getErrorTextById(proc.exitValue()));
// try again with cmd
proc = Runtime.getRuntime().exec(cmd, null, unPackDestinationDirectory);
// any error message?
errorGobbler = new StreamGobbler(proc.getErrorStream(), "ERROR");
// any output?
outputGobbler = new StreamGobbler(proc.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
proc.waitFor();
log.debug("Exit value: " + SysUtils.getErrorTextById(proc.exitValue()));
if (proc.exitValue() != 0) {
// error executing proc
log.warn(" --> Can't execute in retry (with cmd[]): '" + cmd4Log + "'. Exit value: " + proc.exitValue());
log.warn(" --> Can't execute: '" + cmd4Log + "'. " + SysUtils.getErrorTextById(proc.exitValue()));
} else {
log.debug("Succesfully executed in retry: '" + cmd4Log + "'.");
return true;
}
}
}
catch (Exception e) {
log.error("Can't execute: " + cmd4Log, e);
if (proc != null) {
log.error(" --> Can't execute: '" + cmd4Log + "'. Exit value: " + proc.exitValue());
log.error(" --> Can't execute: '" + cmd4Log + "'. " + SysUtils.getErrorTextById(proc.exitValue()));
}
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -