0

I am trying to get a project to pass a string as an argument to another project using Process

If I have a string:

string argString = "Test Argument"

and I want to pass it as an argument to a second project that simply prints out the arguments that are passed to it, how do I pass that string as a single argument? Meaning if I pass argString to my second project, I want args[0] to be: "Test Argument" instead of it breaking the string into two separate arguments separated by the space in the string.

To summarize, I have project 1 that passes a string as an argument to project 2. Inside Project 1 would be:

string argString = "Test Argument";
Process testProcess = new Process();
testProcess.StartInfo.Arguments = argString;
testProcess.StartInfo.FileName = @"LocationOfProject.exe";
testProcess.Start();

And inside Project 2's main method would be:

Console.WriteLine(args[0]);

Currently this would result in project 2 printing "Test" instead of what I want, "Test Argument". Any ides?

Giardino
  • 1,367
  • 3
  • 10
  • 30
  • 3
    string argString = "\"Test Argument\"" – Sten Petrov Jul 18 '14 at 15:38
  • so from the command prompt I would type project1.exe "\"Test Argument\""? – Giardino Jul 18 '14 at 15:39
  • @user1806716 In the command prompt you wouldn't need to escape the quotes, or wrap a string in quotes. To have quotes in a string in C# you need to have the whole thing in quotes (like every other string literal ever), and then use escaped quotes inside of that string. – Servy Jul 18 '14 at 15:40
  • @Servy so if I were to run my app from the command prompt and wanted to pass -f=F Argument as an argument, I would have to basically do some processing of the arguments to make sure I grab the white space between "F" and "Argument" so I treat them as part of the -f=? – Giardino Jul 18 '14 at 15:48

0 Answers0