Problem to define correctly with writeln?

ken76

Member
Joined
Nov 15, 2018
Messages
23
Programming Experience
5-10
I have a problem with this code below this text,
more particularly with this row prog.StandardInput.WriteLine(@"systeminfo | findstr / B / C:"Host Name" / C:"OS Version"");
How to write the line or define it correctly, that will work with this program?

ProcessStartInfo status = new ProcessStartInfo("cmd");
status.UseShellExecute = false;
status.RedirectStandardOutput = true;
status.CreateNoWindow = true;
status.RedirectStandardInput = rue;
var prog = Process.Start(status);

prog.StandardInput.WriteLine(@"systeminfo | findstr / B / C:"Host Name" / C:"OS Version"");
string statustext = prog.StandardOutput.ReadToEnd() richTextBoxStatus.Text = statustext;
richTextBoxStatus.Text = statustext;
 
The point of a verbatim string literal, i.e. a string literal preceded by the @ symbol, is to enable you to use backslashes as a literal character instead of an escape character. They are particularly useful for file and folder paths, which contain backslashes as separators. You have no backslashes in your text so why are you using a verbatim string literal at all?

In a regular string literal, you escape a double-quote with a backslash. In a verbatim string literal, the backslash is not an escape character so you must escape a double-quote with another double-quote, just as is done in VB. You aren't making any attempt to escape your literal double-quotes at all, so they are interpreted as string delimiters and your code is invalid syntax.
 
Back
Top Bottom