C
C#•3y ago
NiftyPixel

Hide cmd output when executed from a Console app?

I'm brand new to C#, am messinga round with VS -- I'm starting cmd.exe w/ some args with > outputdir/file.txt etc at the end so it logs the output to a file.txt (for instance /c hostname > whatever.txt) and this works fine. But it shows that output also in the console window (in addition to appending to file). Is there a way to hide this output? Pseudo Code: Console.WriteLine("checking hostname"); cmd.exe /c hostname > c:\whatever.txt Console.WriteLine("done"); string hostname = ReadAllText(@"c:\whatever.txt"); Console.WriteLine(hostname); I'd like it to basically output: checking hostname done PCsName Currently it's doing checking hostname PCsName done PCsName if that makes any sense 😕 I've goog'd up n down how to hide a cmd window but I believe everything I've found thus far is in regards to hiding a new process from actually popping up -- That's unfort not my issue here. Thank you for the read, patience, and any assistance!
1 Reply
NiftyPixel
NiftyPixelOP•3y ago
I'm using Process.Start("CMD.exe", "/c " + cmd + " > " + output + ""); Aha, thank you, I think RedirectStandardOutput may be the ticket. I believe it's Standard Input/Output/Error Thank you!
Want results from more Discord servers?
Add your server