Avatar of CipherIS
CipherIS
Flag for United States of America asked on

C# ConsolApp opens new window

I'm working on a ConsoleApp.  Right now it's simple.  I will be adding functionality to it.  Write now I'm just passing some values to it and writing the results to the console.  I mostly work on winforms and web.

When I run the consoleapp it opens a new window.  Is there a way to run it and display the results on the same window without opening a new window?
C#.NET Programming

Avatar of undefined
Last Comment
Fernando Soto

8/22/2022 - Mon
Ryan Chong

consider the Console App as a process flow, once it's executed completely, it will be closed. similarly, once you run it, it will open a new window as it's considered as a new process.
CipherIS

ASKER
Is that how it is supposed to run?  Any way to get it to display in the same command window when I execute it?
Fernando Soto

Can you post the code you are using or if it is a small test project can you zip it up and post to a site where we can download it to see what is the issue? Thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
CipherIS

ASKER
I haven't done much yet.  Just testing the consoleapp.  This is what I have right now.  I will expand on it but I want to make sure I'm getting the desired results first.

        public static void Main(string[] args)
        {
            for (int i = 0; i < args.Length; i++)
            {
                Console.WriteLine("{0}", args[i]);
            }

            Console.ReadKey(true);
        }

Open in new window

Fernando Soto

That should open the applications interface which is the console window and all of its output should be going to it.

So are you saying that you are running the command window, cmd.exe, and executing the ConsoleApplication from it and want to the results from the ConsoleApplication to show up on the command window without the ConsoleApplication showing itself?
ASKER CERTIFIED SOLUTION
Fernando Soto

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dmitry G

May be all you need to do is just create an infinite loop in your application?

namespace Looping_in_console
{
    class Program
    {
        static void Main(string[] args)
        {
            bool doContinue = true;
            while (doContinue)
            {
                // read input values
                string input = Console.ReadLine();
                // Do you processing and print results
                // On the next iteration you may continue
                Console.WriteLine("You typed '"+ input + "'");

                // To exit - type "exit", for example
                if (input.ToLower() == "exit")
                {
                    doContinue = false;
                    Console.WriteLine("Good bye!");
                    Console.ReadLine();
                }
            }
        }
    }
}

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CipherIS

ASKER
An infinite loop?
Fernando Soto

Hi CipherIS; did you try my last post?
CipherIS

ASKER
Yes, it didn't work.  Still popped open another window.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Dmitry G

Yes. I'm not quite getting your requirements. If you just need to run your application, enter your data, display results, and repeat it again and again without restarting your console application - you may use the approach I showed in my example. If you need something else - forget.
Fernando Soto

Can you post the steps you took to use the solution I posted, because if you used the /D switch it should not have opened a new window.
CipherIS

ASKER
When I type
start /B AppName.exe ParamsHere

Open in new window

or
start /B /D "Directory Path Here" AppName.exe ParamsHere

Open in new window

They both start the app in a new window.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Fernando Soto

Here is the Microsoft documentation for the DOS command-line command [start] please note the /b switch. It does work like that on my system. I don't understand why it is not working that way on yours. Can you use lower case b in command line? Also what OS version are you using?
CipherIS

ASKER
Windows 10
Fernando Soto

I also am using Windows 10 myself.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck