-1

I realize this looks like a lot of other questions out there, but I looked at all of them for hours and never found the real answer I needed, so hear me out:

This is for a .NET C# console application. Within it, I wanted to call a Windows executable using Process.Start, but without it opening a new console window when run. I also wanted the executable to be able to output to the console and respond to user input normally.

How do you do this? Set ProcessStartInfo.CreateNoWindow, or ProcessStartInfo.WindowStyle? Try to make input/output redirection work for hours on end?


EDIT: smh... this is different from the "possible duplicates" out there because:

  • This is for a console application that wants to run a Windows command seamlessly within itself, as if the command was part of the console application itself. For example: create a new C# console application and make it run the Windows copy command.
  • Additionally, I needed the user to be able to interact with the running command (e.g., if copy asks whether to overwrite I wanted the user to answer), so hiding the window as in this, or this possible answers is a no-no.
  • I wanted to stress how the single UseShellExecute property solves the problem, without the misleading fluff (e.g., about I/O redirection) in answers like this, or this, which again, made me waste hours.
Paul
  • 420
  • 1
  • 5
  • 18
  • Nice... downvotes w/o comment or consideration for how this could prevent someone from wasting hours away... *smh* :-| – Paul Dec 13 '17 at 02:06
  • 1
    I didn't downvote, but I'm a little confused as to how that differs from [this](https://stackoverflow.com/questions/836427/how-to-run-a-c-sharp-console-application-with-the-console-hidden). Are you saying that you're running console application *A* and you want to start executing console application *B* instead "seamlessly" (i.e. make it look like application *B* is just "picking up where *A* left off")? – EJoshuaS - Stand with Ukraine Dec 13 '17 at 04:58
  • 1
    Possible duplicate of [How to run a C# console application with the console hidden](https://stackoverflow.com/questions/836427/how-to-run-a-c-sharp-console-application-with-the-console-hidden) – EJoshuaS - Stand with Ukraine Dec 13 '17 at 05:46
  • @EJoshuaS: Thanks for caring to comment, and yes, seamlessly, and interactive, are the key words! I edited the question and title to hopefully clarify how this is different. – Paul Dec 14 '17 at 05:50
  • 1
    That makes sense, then - I retracted my dupe vote and upvoted b/c this seems like a useful thing to be able to do. – EJoshuaS - Stand with Ukraine Dec 14 '17 at 06:24

1 Answers1

0

Simple: ProcessStartInfo.UseShellExecute=false. That's it! (I know, I couldn't believe it myself).

After hours of trying all sorts of things, this is what worked for me - without even setting CreateNoWindow=true! Also, at the end of it all, I did find this MSDN post that confirms what I found out. Go figure!

Paul
  • 420
  • 1
  • 5
  • 18