Java WMIC 命令在 Unix 中无法识别
Java WMIC command is not recognized in Unix
我正在尝试使用进程从 Java 应用程序执行以下命令:
/bin/wmic -U banshee/allotquery --password=******** //banshee.4g4g.com '--delimiter="|"' 'SELECT eventCode,eventType,timeGenerated,User,InsertionStrings,Message FROM win32_NTLogEvent WHERE Logfile="Security" AND NOT Message LIKE "%$%"'.
(出于安全原因隐藏了密码)。
然后我在 CentOS 6 CLI 中 运行 命令成功,我看到了结果。
当我尝试从我的 Java 应用程序 运行 它时,它无法被识别。
代码:
public final void executeCommand(final String command, final String query) throws IOException {
if (Utils.isNullOrEmpty(query)) {
LogUtils.error(SSHExecClient.class, "No parameters were supplied to the command.");
throw new IOException("No parameters were supplied to the command.");
}
final List<String> cmdTest = new ArrayList<String>();
cmdTest.add(0, "/bin/wmic");
cmdTest.add("-U");
cmdTest.add("banshee/allotquery");
cmdTest.add("--password=******");
cmdTest.add("//banshee.4g4g.com");
cmdTest.add("'--delimiter=\"|\"'");
cmdTest.add("'SELECT eventCode,eventType,timeGenerated,User,InsertionStrings,Message FROM win32_NTLogEvent WHERE Logfile=\"Security\" AND NOT Message LIKE \"%$%\"'");
LogUtils.error(LocalExecClient.class, "Executing command: " + Utils.getAsString(cmdTest, " "));
final ProcessBuilder pb = new ProcessBuilder(cmdTest);
pb.inheritIO();
try {
process = pb.start();
processReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
errReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
process.waitFor();
} catch(final java.io.IOException | InterruptedException e) {
LogUtils.error(LocalExecClient.class, "Unable to execute command.");
LogUtils.error(LocalExecClient.class, e.getMessage());
throw new IOException("Unable to execute command.");
}
}
我得到的结果是(这意味着命令无法识别):
用法:
[-?|--help] [--usage] [-d|--debuglevel DEBUGLEVEL] [--debug-stderr]
[-s|--configfile CONFIGFILE] [--option=name=value]
[-l|--log-basename LOGFILEBASE] [--leak-report] [--leak-report-full]
[-R|--name-resolve NAME-RESOLVE-ORDER]
[-O|--socket-options SOCKETOPTIONS] [-n|--netbiosname NETBIOSNAME]
[-W|--workgroup WORKGROUP] [--realm=REALM] [-i|--scope SCOPE]
[-m|--maxprotocol MAXPROTOCOL] [-U|--user [DOMAIN\]USERNAME[%PASSWORD]]
[-N|--no-pass] [--password=STRING] [-A|--authentication-file FILE]
[-S|--signing on|off|required] [-P|--machine-pass]
[--simple-bind-dn=STRING] [-k|--kerberos STRING]
[--use-security-mechanisms=STRING] [-V|--version] [--namespace=STRING]
[--delimiter=STRING]
//host query
更新: 我最终通过从查询参数中删除所有单引号和双引号解决了这个问题。
原因是它们是由编译器自动添加的。
我最终通过从查询参数中删除所有单引号和双引号解决了这个问题。原因是它们是由编译器自动添加的。
我正在尝试使用进程从 Java 应用程序执行以下命令:
/bin/wmic -U banshee/allotquery --password=******** //banshee.4g4g.com '--delimiter="|"' 'SELECT eventCode,eventType,timeGenerated,User,InsertionStrings,Message FROM win32_NTLogEvent WHERE Logfile="Security" AND NOT Message LIKE "%$%"'.
(出于安全原因隐藏了密码)。
然后我在 CentOS 6 CLI 中 运行 命令成功,我看到了结果。 当我尝试从我的 Java 应用程序 运行 它时,它无法被识别。
代码:
public final void executeCommand(final String command, final String query) throws IOException {
if (Utils.isNullOrEmpty(query)) {
LogUtils.error(SSHExecClient.class, "No parameters were supplied to the command.");
throw new IOException("No parameters were supplied to the command.");
}
final List<String> cmdTest = new ArrayList<String>();
cmdTest.add(0, "/bin/wmic");
cmdTest.add("-U");
cmdTest.add("banshee/allotquery");
cmdTest.add("--password=******");
cmdTest.add("//banshee.4g4g.com");
cmdTest.add("'--delimiter=\"|\"'");
cmdTest.add("'SELECT eventCode,eventType,timeGenerated,User,InsertionStrings,Message FROM win32_NTLogEvent WHERE Logfile=\"Security\" AND NOT Message LIKE \"%$%\"'");
LogUtils.error(LocalExecClient.class, "Executing command: " + Utils.getAsString(cmdTest, " "));
final ProcessBuilder pb = new ProcessBuilder(cmdTest);
pb.inheritIO();
try {
process = pb.start();
processReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
errReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
process.waitFor();
} catch(final java.io.IOException | InterruptedException e) {
LogUtils.error(LocalExecClient.class, "Unable to execute command.");
LogUtils.error(LocalExecClient.class, e.getMessage());
throw new IOException("Unable to execute command.");
}
}
我得到的结果是(这意味着命令无法识别): 用法:
[-?|--help] [--usage] [-d|--debuglevel DEBUGLEVEL] [--debug-stderr]
[-s|--configfile CONFIGFILE] [--option=name=value]
[-l|--log-basename LOGFILEBASE] [--leak-report] [--leak-report-full]
[-R|--name-resolve NAME-RESOLVE-ORDER]
[-O|--socket-options SOCKETOPTIONS] [-n|--netbiosname NETBIOSNAME]
[-W|--workgroup WORKGROUP] [--realm=REALM] [-i|--scope SCOPE]
[-m|--maxprotocol MAXPROTOCOL] [-U|--user [DOMAIN\]USERNAME[%PASSWORD]]
[-N|--no-pass] [--password=STRING] [-A|--authentication-file FILE]
[-S|--signing on|off|required] [-P|--machine-pass]
[--simple-bind-dn=STRING] [-k|--kerberos STRING]
[--use-security-mechanisms=STRING] [-V|--version] [--namespace=STRING]
[--delimiter=STRING]
//host query
更新: 我最终通过从查询参数中删除所有单引号和双引号解决了这个问题。 原因是它们是由编译器自动添加的。
我最终通过从查询参数中删除所有单引号和双引号解决了这个问题。原因是它们是由编译器自动添加的。