예제 #1
0
파일: link.c 프로젝트: WebDrake/dmd
int executecmd(const char *cmd, const char *args)
{
    int status;
    size_t len;

    if (!global.params.quiet || global.params.verbose)
        fprintf(global.stdmsg, "%s %s\n", cmd, args);

    if (!global.params.is64bit)
    {
        if ((len = strlen(args)) > 255)
        {
            char *q = (char *) alloca(8 + len + 1);
            sprintf(q,"_CMDLINE=%s", args);
            status = putenv(q);
            if (status == 0)
            {
                args = "@_CMDLINE";
            }
            else
            {
                error(Loc(), "command line length of %d is too long",len);
            }
        }
    }

    // Normalize executable path separators, see Bugzilla 9330
    char *p = mem.strdup(cmd);
    toWinPath(p);
    cmd = p;

#ifdef _MSC_VER
    if(strchr(cmd, ' '))
    {
        // MSVCRT: spawn does not work with spaces in the executable
        size_t cmdlen = strlen(cmd);
        char* shortName = new char[cmdlen + 1]; // enough space
        DWORD len = GetShortPathName(cmd, shortName, cmdlen + 1);
        if(len > 0 && len <= cmdlen)
            cmd = shortName;
    }
#endif

    status = executearg0(cmd,args);
    if (status == -1)
        // spawnlp returns intptr_t in some systems, not int
        status = spawnlp(0,cmd,cmd,args,NULL);

//    if (global.params.verbose)
//      fprintf(global.stdmsg, "\n");
    if (status)
    {
        if (status == -1)
            printf("Can't run '%s', check PATH\n", cmd);
        else
            printf("--- errorlevel %d\n", status);
    }
    return status;
}
예제 #2
0
파일: link.c 프로젝트: shoo/dmd
int executecmd(char *cmd, char *args, int useenv)
{
    int status;
    size_t len;

    if (!global.params.quiet || global.params.verbose)
    {
        printf("%s %s\n", cmd, args);
        fflush(stdout);
    }

    if (global.params.is64bit)
    {
    }
    else
    {
    if ((len = strlen(args)) > 255)
    {   char *q;
        static char envname[] = "@_CMDLINE";

        envname[0] = '@';
        switch (useenv)
        {   case 0:     goto L1;
            case 2: envname[0] = '%';   break;
        }
        q = (char *) alloca(sizeof(envname) + len + 1);
        sprintf(q,"%s=%s", envname + 1, args);
        status = putenv(q);
        if (status == 0)
            args = envname;
        else
        {
        L1:
            error(0, "command line length of %d is too long",len);
            }
        }
    }

    status = executearg0(cmd,args);
#if _WIN32
    if (status == -1)
        status = spawnlp(0,cmd,cmd,args,NULL);
#endif
//    if (global.params.verbose)
//      printf("\n");
    if (status)
    {
        if (status == -1)
            printf("Can't run '%s', check PATH\n", cmd);
        else
            printf("--- errorlevel %d\n", status);
    }
    return status;
}
예제 #3
0
파일: link.c 프로젝트: alexrp/dmd
int executecmd(char *cmd, char *args, int useenv)
{
    int status;
    size_t len;

    if (!global.params.quiet || global.params.verbose)
    {
        printf("%s %s\n", cmd, args);
        fflush(stdout);
    }

    if (global.params.is64bit)
    {
    }
    else
    {
    if ((len = strlen(args)) > 255)
    {   char *q;
        static char envname[] = "@_CMDLINE";

        envname[0] = '@';
        switch (useenv)
        {   case 0:     goto L1;
            case 2: envname[0] = '%';   break;
        }
        q = (char *) alloca(sizeof(envname) + len + 1);
        sprintf(q,"%s=%s", envname + 1, args);
        status = putenv(q);
        if (status == 0)
            args = envname;
        else
        {
        L1:
            error(Loc(), "command line length of %d is too long",len);
            }
        }
    }

#if _WIN32
    // Normalize executable path separators, see Bugzilla 9330
    for (char *p=cmd; *p; ++p)
        if (*p == '/') *p = '\\';
#endif

    status = executearg0(cmd,args);
#if _WIN32
    if (status == -1)
        // spawnlp returns intptr_t in some systems, not int
        status = spawnlp(0,cmd,cmd,args,NULL);
#endif
//    if (global.params.verbose)
//      printf("\n");
    if (status)
    {
        if (status == -1)
            printf("Can't run '%s', check PATH\n", cmd);
        else
            printf("--- errorlevel %d\n", status);
    }
    return status;
}