2017-03-26 3 views
1

에 인식되지 않는 나는 프로세스를 사용하여 Java 응용 프로그램에서 다음 명령을 실행하기 위해 노력하고있어 :자바 WMIC 명령이 유닉스

/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 

업데이트 : 나는 마침내 모두 제거하여 문제를 해결 쿼리 매개 변수의 작은 따옴표 및 큰 따옴표 그 이유는 컴파일러에 의해 자동으로 추가된다는 것입니다.

답변

0

마지막으로 쿼리 매개 변수에서 작은 따옴표와 큰 따옴표를 모두 제거하여 문제를 해결했습니다. 그 이유는 그들이 컴파일러에 의해 자동으로 추가된다는 사실입니다.

관련 문제