[erlang-questions] how to open_port with spaces in path - patch for emulator to accept quoted commands
David Hopwood
david.nospam.hopwood@REDACTED
Tue Feb 13 17:10:04 CET 2007
Denis Bilenko wrote:
> --- otp_src_R11B-3-original\erts\emulator\sys\win32\sys.c Mon
> Jan 29 18:52:58 2007
> +++ otp_src_R11B-3\erts\emulator\sys\win32\sys.c Tue Feb 13 17:47:59 2007
> @@ -1104,6 +1104,9 @@
> int cmdlength;
> char* thecommand;
> HANDLE hProcess = GetCurrentProcess();
> +
> + char* thecommand_start = origcmd;
> + int thecommand_length;
>
> siStartInfo.cb = sizeof(STARTUPINFO);
> siStartInfo.dwFlags = STARTF_USESTDHANDLES;
> @@ -1116,9 +1119,26 @@
> * contain spaces).
> */
> cmdlength = parse_command(origcmd);
> - thecommand = (char *) erts_alloc(ERTS_ALC_T_TMP, cmdlength+1);
> - strncpy(thecommand, origcmd, cmdlength);
> - thecommand[cmdlength] = '\0';
> +
> + /*
> + * for quoted argument, parse_command will return quoted result, i.e.
> + * "\"C:/Program Files/abc.exe\" arg1" -> "\"C:/Program Files/abc.exe\""
> + * Such an argument will cause GetFileAttributes to return
> + * INVALID_FILE_ATTRIBUTES, which will cause ApplicationType to
> + * return APPL_NONE.
> + *
> + * Cut the quotes out of command.
> + */
> + if (cmdlength > 1 && origcmd[0]=='\"' && origcmd[cmdlength-1]=='\"')
> + {
> + thecommand_start = origcmd + 1;
> + thecommand_length = cmdlength - 2;
> + }
> + else thecommand_length = cmdlength;
> +
> + thecommand = (char *) erts_alloc(ERTS_ALC_T_TMP, thecommand_length+1);
> + strncpy(thecommand, thecommand_start, thecommand_length);
Not related to the original problem, but: can erts_alloc return NULL?
> + thecommand[thecommand_length] = '\0';
> DEBUGF(("spawn command: %s\n", thecommand));
>
> applType = ApplicationType(thecommand, execPath);
--
David Hopwood <david.nospam.hopwood@REDACTED>
More information about the erlang-questions
mailing list