2017-03-26 6 views
1

で認識されていない私は、プロセスを使用してJavaアプリケーションから次のコマンドを実行しようとしている:JavaのWMICコマンドはUnixの

/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 

UPDATE:私は最終的にすべて削除することで問題を解決しクエリパラメータからの単一引用符と二重引用符。 その理由は、コンパイラによって自動的に追加されるためです。

答えて

0

最後に、クエリパラメータからすべての一重引用符と二重引用符を削除して問題を解決しました。その理由は、コンパイラによって自動的に追加されるためです。