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
Escaping quotes - portable way #15812
Comments
I'm going to ignore your sarcasm. What exactly do you expect to happen on Linux and OS X? |
The reason Process does not support UseShellExecute is because there is no good way to support it in OneCore. The underlying windows APIs are not available. Also, as Stephen mentioned what do you expect the behavior to be cross-plat? |
@krwq Let me know your thoughts on this? Since we are looking at the surface area gap, I would like to make sure, I am accounting for any issues raised. |
Perhaps some related information can be found here: http://developer.xamarin.com/api/property/System.Diagnostics.ProcessStartInfo.UseShellExecute/. Probably can be accomplished by storing list of known terminals |
Thanks for the suggestion. However what you are asking for seems like a new functionality rather than a behavior for UseShellExecute. @krwq Unfortunately, I don't think we can bring forward UseShellExecute due to platform limitations. However, if you would like Process to support a scenario, please propose a new API and I will be happy to take a look at it. |
For the ShellExecute from the name means execute as default shell does it on a given OS so what @jasonwilliams200OK is exactly what I was expecting would happen. Something similar to what would happen in c++ when I called system("command args") For the quotes - each shell has some mechanism of escaping quotes. I'm expecting either string[] overload so that the problem dissappears or something for escaping quotes - if we know how to split the string we should know how to join it |
We don't really know how to do that; the command line arguments are already parsed when they gets to us (in the form of an array). Is that what you meant? I recall that we decided against against exposing |
We can use: |
@krwq How would we implement this on windows? The OS does not support the necessary functionality on OneCore. |
We have Windows source code and we can check what they are doing in CommandLineToArgvW and reverse the process We actually have this: https://msdn.microsoft.com/en-us/library/xwy0k9bb.aspx |
Also all the rules are here: |
Sorry now I am a little confused now. Are you asking for UseShellExecute or do you simply want a way to pass arguments to the Process? The issue you created is a little wage. |
I want to be able to use argv[] and be able to pass that or part of it to ShellExecute (or some platform independent way of escaping characters so i can do it myself) |
Ahh thanks I understand the scenario a little bit more. Environment.GetCommandLineArgs() does provide you a way to get argv[] although its implementation is host specific i.e. it is dependent on how host is configured and what it passes to the runtime as process arguments. That should do most of what you are wanting to do. Using CommandLineToArgvW in a hosted app is risky. It simply will give you the complete commandLine that was passed to the windows. It has no knowledge of what and how host consumes it. And in a ton of scenarios like in an f# script or PS script, the developer also does not know what the host does, because all that happens in the background and is hidden from him. The part where you want to pass these arguments to ShellExecute is something that can't be supported. However, we can support passing these arguments to CreateProcess, which I believe will also do the trick for you. Is that right? |
Thanks, passing argv to CreateProcess sounds good to me and I think that should unblock most of the common scenarios. 😃 I was thinking of ShellExecute as something similar to running "cmd /c commandline" on Windows without the host scenarios in my head. |
We need an api proposal for this, marking it as up for grabs.. |
Here is example missing scenario for further reference:
It is not simply string.Join as some of the args require escaping, quotes etc and the syntax might be different depending on OS. The worst possible test case scenario is probably passing regex with spaces as it can contain any different kind of characters like ^ which is used as escape character on windows |
@Priya91 - I actually think that this is more broken than I thought: I hit this today - basically when you try to pass the path wrapped with quotes and ending with \ it is not working as expected |
Here's a usecase for the scenario: dotnet/corefx#21196 (comment) Also sample parsing code: https://github.com/AtsushiKan/test/blob/master/Paste.cs |
I beleave https://github.com/dotnet/corefx/issues/23592 is closely related. It's not about Regarding
Passing EDIT:
|
Maybe this should be closed as duplicate of https://github.com/dotnet/corefx/issues/19956 or https://github.com/dotnet/corefx/issues/23592 |
Closing as dup. |
How do you escape quotes the portable way when using Process with UseShellExecute and Arguments?
EDIT:
UseShellExecute:
Process could perhaps have an option of taking string[] to match Main and be able roundtrip
The text was updated successfully, but these errors were encountered: