Подтвердить что ты не робот

Unix "какая java" эквивалентная команда на windows?

Возможный дубликат:
Есть ли эквивалент ', который в окнах?

Не удалось найти его в Google, но просто задается вопросом, есть ли способ показать местоположение Java через эквивалентную команду из приглашения Windows.

В основном у меня есть информация от клиента, что он не устанавливает JAVA_HOME, но все еще может запускать Java-программы. Я подозреваю, что тогда это необходимо, потому что путь к этой java задан в переменной среды PATH системы, но это слишком долго для быстрой итерации, также очень болезненной (приходится копать в подпапки).

Спасибо за любое предложение заранее!

4b9b3361

Ответ 1

Вы можете попробовать:

c:\> for %i in (java.exe) do @echo.   %~$PATH:i
   C:\WINDOWS\system32\java.exe

Это функция команды Windows for, и вы можете использовать for /? для получения информации:

In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:
    %~I         - expands %I removing any surrounding quotes (")
    %~fI        - expands %I to a fully qualified path name
    %~dI        - expands %I to a drive letter only
    %~pI        - expands %I to a path only
    %~nI        - expands %I to a file name only
    %~xI        - expands %I to a file extension only
    %~sI        - expanded path contains short names only
    %~aI        - expands %I to file attributes of file
    %~tI        - expands %I to date/time of file
    %~zI        - expands %I to size of file
    %~$PATH:I   - searches the directories listed in the PATH
                   environment variable and expands %I to the
                   fully qualified name of the first one found.
                   If the environment variable name is not
                   defined or the file is not found by the
                   search, then this modifier expands to the
                   empty string

The modifiers can be combined to get compound results:
    %~dpI       - expands %I to a drive letter and path only
    %~nxI       - expands %I to a file name and extension only
    %~fsI       - expands %I to a full path name with short names only
    %~dp$PATH:I - searches the directories listed in the PATH
                   environment variable for %I and expands to the
                   drive letter and path of the first one found.
    %~ftzaI     - expands %I to a DIR like output line

In the above examples %I and PATH can be replaced by other valid
values.  The %~ syntax is terminated by a valid FOR variable name.
Picking upper case variable names like %I makes it more readable and
avoids confusion with the modifiers, which are not case sensitive.

Ответ 2

Я что-то упустил? Как пробовать следующие простые командные строки?

c: > dir/s java.exe

или

c: > dir/s javaw.exe

Им потребуется время, но они будут работать. Если вы хотите сделать это быстрее, начните с "c:\Program files"

Ответ 3

Вот что я обычно использую. Если бы я делал это снова сегодня, я бы сделал это немного по-другому, но он работает достаточно хорошо, что у меня на самом деле не было причин смотреть на него в течение многих лет (на самом деле, я уверен, что в последний раз Я сделал все, чтобы добавить "cmd" в список расширений, когда я портировал его из DOS в Win32...

// Which.c:
#include <io.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *extensions[] = { "com", "exe", "bat", "cmd", NULL };

int is_exe(char *ext) {

    int i;

    for ( i = 0; extensions[i]; i++)
        if ( 0 == stricmp(ext, extensions[i] ) )
            return 1;
    return 0;
}

int main(int argc, char **argv) {

    char path[FILENAME_MAX];
    char buffer[FILENAME_MAX];
    char *path_var;
    char *ext;
    char *dir;
    int i;

    if (argc != 2) { 
        fprintf(stderr, "Usage: which <filename>\n");
        return 1;
    }

/* First try to find file name as-is.
 */
    if ( 0 == access(argv[1], 0)) {
        printf("\n%s", argv[1]);
        return 0;
    }

/* Okay, it wasn't found.  See if it had an extension, and if not, try
 * adding the usual ones...
 */

    ext = strrchr(argv[1], '.' );

    if ( 0 == ext++ || !is_exe(ext) ) {
        for ( i = 0; extensions[i]; i++) {

            sprintf(buffer, "%s.%s", argv[1], extensions[i]);

            if ( 0 == access(buffer, 0)) {
                printf("\n%s", buffer);
                return 0;
            }
        }

        if ( NULL == (path_var=getenv("PATH")))
            return 1;

        dir = strtok(path_var, ";");
        do {
            for ( i = 0; extensions[i]; i++) {

                sprintf(buffer, "%s\\%s.%s", dir, argv[1], extensions[i]);

                if ( 0 == access( buffer, 0)) {
                    printf("\n%s", buffer);
                    return 0;
                }
            }
        } while ( NULL != ( dir = strtok(NULL, ";")));
    }

    else {
        if ( NULL == (path_var=getenv("PATH")))
            return 1;

        dir = strtok(path_var, ";");
        do {
            sprintf(buffer, "%s\\%s", dir, argv[1]);

            if ( 0 == access( buffer, 0)) {
                printf("\n%s", buffer);
                return 0;
            }
        } while ( NULL != ( dir = strtok(NULL, ";")));
    }
    return 1;
}

Ответ 4

Другие ответы выглядят хорошо. Для полноты я добавлю, что вы также можете распространять JRE с вашим приложением. Это не так элегантно, как другие решения, но он будет работать, и вам не придется беспокоиться о том, какая версия java-клиента имеет.