-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic parameter escaping in syscall.StarProcess on windows is too restrictive #1849
Labels
Comments
Owner changed to @alexbrainman. |
The current API does the right thing with C-based windows program that don't directly access the command line. Therefore I cannot write an example program without extending the API or it would break valid programs... All I can say is : there is currently no way to execute the following command : cmd.exe /s /c "cd "C:\Program Files" && dir" (I should also mention that the python subprocess.Popen function allows to pass a string instead of a command line on windows (http://docs.python.org/library/subprocess.html, 17.1.1) and does not suffer from this restriction.) A possible alternative that would fix all my cases would be to not apply any escaping for an argument if it is already enclosed with quotes. I believe this would then automatically handle both the cmd.exe and Delphi program cases without any API changes... Programs needing explicit escaping then can do the escaping before passing the argument down to os.StartProces & co. Any opinion ? Vincent |
Hi, I'm attaching a sample program that will probably better explains the problem. I'm also attaching a custom version of syscall/exec_windows.go with a possible alternative. Any alternative/suggestion welcome (I'm not attached to any particular solution to this problem, I just need one that works...). Thanks, Vincent Attachments:
|
Vincent, You could replace argument list with this: args_cmd := []string{"cmd", "/c", "cd", `C:\Program Files`, "&&", "dir", "/a", "/b"} to get your example to work. But I can see your problem now. I think, in essence, the problem is that cmd.exe (ms own) and some others don't use syscall.CommandLineToArgv to parse command line into arguments, but employ some of their own algorithm to do it. Is that a fare description? If that is the case, then I agree with you, I can't see any other way, but to provide go users with a way to not use "standard" procedure of encoding arguments into command line, but to employ their own. Your proposed change http://golang.org/cl/4548050/ looks simple enough, but there is too much mystery / magic in it - user needs to remember to put 0 as first char of parameters it doesn't want to escape. I would rather do something similar to your original proposal. Perhaps, we could have new field ProcAttr.CmdLine: type ProcAttr struct { Dir string Env []string Files []int HideWindow bool } CmdLine string where user can specify "command line" encoded and escaped to his / her taste. syscall.StartProcess will check for ProcAttr.CmdLine not empty and use it, ignoring argv. Russ, please comment. Alex Labels changed: added os-windows, packagechange. Status changed to Accepted. |
This issue was closed by revision f18a4e9. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: