StackOverflow keeps proving as the best source of programming knowledge for me! This is because of you, because of your desire to give the best possible answer and help to guys like me, who are struggling. Thank you!
As I always do, I did a research on the topic for a couple of hours and it seems that the problem I'm facing is a bit specific (probably that's why I couldn't find a solution and am asking this question now). Here and here I found solutions, which are the closest and mostly related to my problem, but not enough. What I need to do is start a console app (.exe written in C). It is expecting any given arguments to arrive in here: int main(int argc, char** argv) -> in argv as usual. One of those args includes spaces. I tested and found out, that wrapping the string in this arg with double-quotes solves the issue with spaces. When debugging in VS2010, I set Command Arguments to: first second "third fourth" and I get three arguments as I should: argv[0] = first, argv1 = second, argv2 = third fourth (w\o the quotes) and that is exactly what I need. However, when I try to do something like this:
procInfo = new System.Diagnostics.ProcessStartInfo();
procInfo.FileName = "myProg.exe";
procInfo.Arguments = "first second \"third fourth\"";
and when debugging, I see, that procInfo.Arguments = first second \"third fourth\", while I need it to be first second "third fourth". The bad thing about all this is that this is the way those args arrive at myProg.exe: first second \"third fourth\". When debugging myProg in Visual Studio and setting Command Arguments to first second \"third fourth\", then
argv[0] = first,
argv1 = second,
argv2 = "third (yes, with that double-quote at the beginning) I need argv2 = third fourth, not "third
and argv[3] is (null) as it should be.
The problem is that procInfo.Arguments = "first second \"third fourth\"", while I need it to be procInfo.Arguments = "first second "third fourth""; In JavaScript I can write such strings as 'first second "third fourth"'. I wish in C# there was a similar thing (or maybe there is, I don't know). In the code, I tried procInfo.Arguments = @"first second ""third fourth""", but this gets converted to this: first second \"third fourth\" (I don't think this is the way it should work, but you could tell me am I right ro not).
myProc.Arguments = $"first second ..."; is giving me: "Unexpected character '$'"
Once again, when debugging, when I set Command Arguments to first second "third fourth" I get them as first; second; third fourth; without any quotes and this way myProg is working like a charm. So this is the way I want the args to look like.
Thank you in advance for your help!
EDIT: I even tried:
procInfo.Arguments = "first second ";
procInfo.Arguments += '"';
procInfo.Arguments += "third fourth";
procInfo.Arguments += '"';
but I'm getting the same result.
EDIT2: When writing in code:
procInfo.Arguments = "first second \'third fourth\' fifth";
when debugging (hovering over procInfo.Arguments) I get it as "first second 'third fourth' fifth", while with double quotes, I get it as "first second \"third fourth\" fifth", while I expect it to show as "first second "third fourth" fifth" like with the single-quotes. I know, that the outer quotes are just from the debugger and are not sent to myProg.exe. The problem is, that single-quotes don't do the trick, which is as expected.
EDIT3: I just tried: procInfo.Arguments = "first second \x22third fourth\x22" and procInfo.Arguments = "first second \u0022third fourth\u0022", but the result is once again "first second \"third fourth\""