-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Problem parsing on single quotes in argument for Process.Start (dotnet Core, Linux console) #28662
Comments
According to sources it follows https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017 rules |
.NET Core added an ArgumentsList on ProcessStartInfo. You don't need to deal with escaping if you are using that. |
thanks....I'll check it out :-) |
@MrM40 Is this now working for you? Can the issue be closed? |
Well, kind of:-P |
As mentioned by @EgorBo , this applies: https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017. Have you tried following those escape rules? |
Yes, doesn't work. Result: |
The single quotation is showing up here. Single quotation is also not mentioned in https://docs.microsoft.com/en-us/cpp/cpp/parsing-cpp-command-line-arguments?view=vs-2017. Try using |
The issue isn't really to get the command working, the issue is the string-parsing it supposed to parse whatever I tell it to parse! If I have a argument that need single quotation, I should be able to! |
You want to start the executable To do this with a shell, you type something like:
The single quotations that show up here are meant for the shell. It uses them to figure out that When using You need to follow the rules of the thing that splits the string into separate arguments. |
But I believe I've tried this: It would help a lot if you could tell how the |
Try replacing the single quotes with double quotes: |
The |
You want to start the application from .NET Core which you start on the command line as:
Let's first figure out how many arguments are involved when starting the application. We'll use strace and trace for the execve call:
As we can see in the output, two arguments are passed to We need a way of passing the second argument so it gets treated as a whole (that is, not split at the spaces). For bash, there are a number of options. One is to use single quotes, like For static void Main(string[] args)
{
Process.Start(
new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = "-c \"ls -l /etc/ > /tmp/list.txt\""
}
).WaitForExit();
if (File.Exists("/tmp/list.txt"))
{
System.Console.WriteLine("The file exists!");
}
} prints out:
|
I think this issue could be closed as duplicate of https://github.com/dotnet/corefx/issues/38483 because it essentially asks to make the behavior of @MrM40 Currently |
But the whole problem is, which is not covered by 38483, that the single quote |
In https://github.com/dotnet/corefx/issues/23592#issuecomment-514215957 you wrote
I agree - and that is absolutely possible with the current behavior. You also wrote:
I agree again, however they don't need to be parsed - they are just passed unchanged to the called program. Anyway, I'd strongly recommend, that you use the new argument array API on linux - |
Which example do you mean, this one?
What exactly do you mean by "parsed as a normal character"? Can we agree, that
searches for a file or folder By the same logic your first example I guess that is not what you want, so you actually don't want |
The command Are you takling about |
works fine for me. If you want |
OMG!!!! |
No no no! Please delete (or edit) your comment https://github.com/dotnet/corefx/issues/23592#issuecomment-514241549 as it could heavily confuse newcomers. |
If you execute
|
Hmmm.....not so easy :-( |
@MrM40
|
I'm working on it :-P (don't have sdk on the prod server where I run the commands) |
@jnm2 I'm confused, shouldn't it be
and
If you execute
as output, so |
Yes. As it turn out when using the In the Linux shell:
In the Linux shell:
|
@TSlivede Yes, I wasn't thinking. Thanks! |
(2019-07-21: rewrote this issues to simplify)
I'm executing console programs in Linux using
I'm executing programs on Linux with Process.Start.
Sometimes I need to provide single quotes in the arguments but I've not been able to succeed no matter how I escape the character.
A simplified example:
I do know I don't have to surround /tmp/ in single quote, but it's just to make a simple example (please don't suggest alternatives, that's not the issue!)
The err.out from this example is
ls: cannot access "'/tmp/'": No such file or directory
I've tried to run this code in .net Core 2.2 and the newest .net Core 3.0.100-preview6-012264 in both C# and VB.
I also tried to use the
ProcessStartInfo.ArgumentList
it doesn't parse single quotes any better.The text was updated successfully, but these errors were encountered: