#endif
#ifdef _WIN32
-char *win32argvtos(char *prefix, char **argv);
+char *win32argvtos(char *prefix, char **argv, int *length);
char *win32getshell(char *path);
int win32execute(char *path, char **argv, int doreturn,
int fd_stdout, int fd_stderr);
// Re-create a win32 command line string based on **argv.
// http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
char *
-win32argvtos(char *prefix, char **argv)
+win32argvtos(char *prefix, char **argv, int *length)
{
int i = 0;
int k = 0;
+ *length = 0;
char *arg = prefix ? prefix : argv[i++];
do {
int bs = 0;
if (!str) {
return NULL;
}
+ *length = k;
i = 0;
arg = prefix ? prefix : argv[i++];
}
}
- char *args = win32argvtos(sh, argv);
+ int length;
+ char *args = win32argvtos(sh, argv, &length);
const char *ext = strrchr(path, '.');
char full_path_win_ext[MAX_PATH] = {0};
add_exe_ext_if_no_to_fullpath(full_path_win_ext, MAX_PATH, ext, path);
- BOOL ret =
- CreateProcess(full_path_win_ext, args, NULL, NULL, 1, 0, NULL, NULL,
- &si, &pi);
+ BOOL ret = FALSE;
+ if (length > 8192) {
+ char *tmp_file = format("%s.tmp", path);
+ FILE *fp = create_tmp_file(&tmp_file, "w");
+ char atfile[MAX_PATH + 3];
+ fwrite(args, 1, length - 1, fp);
+ fclose(fp);
+ if (ferror(fp)) {
+ cc_log("Error writing @file; this command will probably fail:\n%s", args);
+ }
+ snprintf(atfile, sizeof(atfile), "\"@%s\"", tmp_file);
+ ret = CreateProcess(NULL, atfile, NULL, NULL, 1, 0, NULL, NULL,
+ &si, &pi);
+ }
+ if (!ret) {
+ ret = CreateProcess(full_path_win_ext, args, NULL, NULL, 1, 0, NULL, NULL,
+ &si, &pi);
+ }
if (fd_stdout != -1) {
close(fd_stdout);
close(fd_stderr);