Click here to Skip to main content
15,887,467 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created one console application and when i run project console application.exe runs and shows command prompt , and what i have to do is works fine on this prompt(exe) but i want to run it on (cmd.exe) from where i have to receive input so my question is "How to run console application on cmd.exe?"

C#
namespace ConsoleApplication2
{
    class Program
    {
        public static void Main(string[] args)
        {
            Program p = new Program();
            p.getConsoleInput();// TAKING STRING FROM PROMPT
            p.ReadWriteIntoFile();//generate txt file and dump string into it//
            p.WriteFileOutput();// this put related data according to string into another text file.//
        }
    }
}
Posted
Updated 16-May-15 1:43am
v3
Comments
OriginalGriff 16-May-15 6:56am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
You're going to have to give a better example, and explain what problem you are having trying to get it to work.
Use the "Improve question" widget to edit your question and provide better information.
deepgalley 16-May-15 7:39am    
What you are trying to do actually?
Member 11543226 16-May-15 7:49am    
want to run my console application project on windows cmd.exe because from there i got string and i have to use this string for further process.
Tomas Takac 16-May-15 8:59am    
Do you mean command line arguments?

1 solution

If you want invoke your exe form a console you have to use one of the switches /c or /K of 'cmd' that executes the command following the switch:
C#
string strCmdPars;
strCmdPars= "/C application.exe";
System.Diagnostics.Process.Start("CMD.exe",strCmdPars);

This will run cmd.exe that in turn will run your application. When the application ends cmd will quit.
Using the switch /K cmd will remain on after application.exe quits:
C#
string strCmdPars;
strCmdPars= "/K application.exe";
System.Diagnostics.Process.Start("CMD.exe",strCmdPars);

For all switches accepted by cmd.exe you can see here[^].
 
Share this answer
 
Comments
Member 11543226 18-May-15 1:34am    
i used this lines of code it works also but when i call method containing these lines it opens cmd windows multiple run continuously and not stops , why this happened?
Frankie-C 18-May-15 4:47am    
Are you trying to launch the same executable that in turn relaunch itsels and so on?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900