{"action":"created","issue":{"url":"https://api.github.com/repos/ldc-developers/ldc/issues/1165","labels_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1165/labels{/name}","comments_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1165/comments","events_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1165/events","html_url":"https://github.com/ldc-developers/ldc/pull/1165","id":111976940,"number":1165,"title":"Windows: fix command line when invoking linker batch file","user":{"login":"kinke","id":1889215,"avatar_url":"https://avatars.githubusercontent.com/u/1889215?v=3","gravatar_id":"","url":"https://api.github.com/users/kinke","html_url":"https://github.com/kinke","followers_url":"https://api.github.com/users/kinke/followers","following_url":"https://api.github.com/users/kinke/following{/other_user}","gists_url":"https://api.github.com/users/kinke/gists{/gist_id}","starred_url":"https://api.github.com/users/kinke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kinke/subscriptions","organizations_url":"https://api.github.com/users/kinke/orgs","repos_url":"https://api.github.com/users/kinke/repos","events_url":"https://api.github.com/users/kinke/events{/privacy}","received_events_url":"https://api.github.com/users/kinke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-17T18:19:51Z","updated_at":"2015-10-18T07:14:54Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ldc-developers/ldc/pulls/1165","html_url":"https://github.com/ldc-developers/ldc/pull/1165","diff_url":"https://github.com/ldc-developers/ldc/pull/1165.diff","patch_url":"https://github.com/ldc-developers/ldc/pull/1165.patch"},"body":"This command line sent to CreateProcess():\r\n\r\n```\r\n\"C:\\LDC\\bin\\amd64.bat\" 1 2 \"3\" 4\r\n```\r\n\r\nis internally transformed to:\r\n\r\n```\r\nC:\\Windows\\system32\\cmd.exe /c \"C:\\LDC\\bin\\amd64.bat\" 1 2 \"3\" 4\r\n```\r\n\r\nNow guess what - cmd.exe treats the command string after /c or /k in a very special way if it begins with double quotes and is followed by other quoted args. In this example, it tries to invoke:\r\n\r\n```\r\nC:\\LDC\\bin\\amd64.bat\" 1 2 \"3\r\n```\r\n\r\nAnother example: `C:\\Windows\\system32\\cmd.exe /c \"C:\\L D C\\bin\\amd64.bat\" 1 2 \"3\" 4` => `C:\\L`\r\n\r\nThe fix seems to be enclosing the whole command with additional double quotes (but no additional escaping of the command!) and using `/s` for cmd.exe:\r\n\r\n```\r\nC:\\Windows\\system32\\cmd.exe /s /c \"\"C:\\L D C\\bin\\amd64.bat\" 1 2 \"3\" 4\"\r\n```\r\n\r\nSo the command is quoted, but not escaped, i.e., no regular argument to cmd.exe, so we can't use LLVM's executeAndWait() to launch the cmd.exe process. :/\r\n\r\nAdditionally, LLVM's arg-quoting code is not public, so we can't use it to quote & escape the regular args inside the command.\r\n\r\nI therefore implemented a simple `quoteArgs()` variant which should suffice for our use cases."},"comment":{"url":"https://api.github.com/repos/ldc-developers/ldc/issues/comments/148986367","html_url":"https://github.com/ldc-developers/ldc/pull/1165#issuecomment-148986367","issue_url":"https://api.github.com/repos/ldc-developers/ldc/issues/1165","id":148986367,"user":{"login":"rainers","id":702284,"avatar_url":"https://avatars.githubusercontent.com/u/702284?v=3","gravatar_id":"","url":"https://api.github.com/users/rainers","html_url":"https://github.com/rainers","followers_url":"https://api.github.com/users/rainers/followers","following_url":"https://api.github.com/users/rainers/following{/other_user}","gists_url":"https://api.github.com/users/rainers/gists{/gist_id}","starred_url":"https://api.github.com/users/rainers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rainers/subscriptions","organizations_url":"https://api.github.com/users/rainers/orgs","repos_url":"https://api.github.com/users/rainers/repos","events_url":"https://api.github.com/users/rainers/events{/privacy}","received_events_url":"https://api.github.com/users/rainers/received_events","type":"User","site_admin":false},"created_at":"2015-10-18T07:14:54Z","updated_at":"2015-10-18T07:14:54Z","body":"LG, fixes both issues 1160 and 1152 for me."}}