Skip to content
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

Parameters and quotes - wrong implementation #73

Closed
tomasr78 opened this issue May 5, 2020 · 1 comment
Closed

Parameters and quotes - wrong implementation #73

tomasr78 opened this issue May 5, 2020 · 1 comment
Labels

Comments

@tomasr78
Copy link

tomasr78 commented May 5, 2020

Could you let me know how to pass such a parameter?

user="this is the password"

The MedallionShell adds additional quotes on top of the current parameter.
If I split one parameter to two like this

user=
this is the password

It adds space between parameters and it becomes user= "this is the password" and command line breaks.

@madelson
Copy link
Owner

madelson commented May 5, 2020

@tomasr78 what token(s) do you want the program to receive? What OS are you using?

If you want to send 2 tokens user= and this is the password, you should pass new[] { "user=", "\"this is the password\"" } to the command.

If you want to send just one token user=\"this is the password\", then you should pass just one token new[] { "user=\"this is the password\"" }.

A rare possibility is that you are dealing with a legacy program (likely written in a low-level language) that doesn't comply with the OS rules for how arguments should be escaped/tokenized. In this case, neither of the above will get you the desired behavior. To work around this, you can use a StartInfo initializer instead of passing explicit arguments:

Command.Run(
    "some.exe", 
     Array.Empty<object>(), 
     options: o => o.StartInfo(si => si.Arguments = "whatever string I want")
);

While this last case is theoretically possible from what I've read, in practice I've yet to come across a case where this was required. It is risky because you are giving up built-in command line escaping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants