question

KenEkholm-3624 avatar image
0 Votes"
KenEkholm-3624 asked Viorel-1 edited

Problem to define correctly with writeln?

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;

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Try this code:

 ProcessStartInfo status = new ProcessStartInfo( "cmd" );
 status.Arguments = "/c systeminfo | findstr /B /C:\"Host Name\" /C:\"OS Version\"";
 status.UseShellExecute = false;
 status.CreateNoWindow = true;
 status.WindowStyle = ProcessWindowStyle.Hidden;
 status.RedirectStandardOutput = true;
 status.RedirectStandardInput = false;
 var prog = Process.Start( status );
 string statustext = prog.StandardOutput.ReadToEnd( );

Then display the result in your textbox.

You can also get the whole information without findstr, then extract the details, or use some equivalent library functions.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.