gpt4 book ai didi

Unix 中无法识别 Java WMIC 命令

转载 作者:太空宇宙 更新时间:2023-11-04 11:38:29 24 4
gpt4 key购买 nike

我正在尝试使用进程从 Java 应用程序执行以下命令:

/bin/wmic -U banshee/allotquery --password=********//banshee.4g4g.com '--delimiter="|"' 'SELECT eventCode,eventType,timeGenelated,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

更新:我最终通过从查询参数中删除所有单引号和双引号解决了该问题。原因是它们是由编译器自动添加的。

最佳答案

我最终通过从查询参数中删除所有单引号和双引号解决了该问题。原因是它们是由编译器自动添加的。

关于Unix 中无法识别 Java WMIC 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43030383/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com