How to tell if an application is running in GUI mode or command line

Source: Internet
Author: User

More and more applications are provided to run on a command-line basis, there are two common approaches: Write a console program that runs on a command line for the application alone, and it must run on a command-line basis when the user runs the program, and share an application or EXE file with the GUI and command line. But through the different arguments to judge, finally does the different processing separately.

For the console program that writes the application based on the command line alone, it is simply to identify and set the parameters required for the program to run by judging the args array passed, and finally set the parameters to complete the required work. The Help menu for/? is recommended here for easy user inquiries.

if (args.  Length!= 1)
{
Console.WriteLine ("Error:invalid Argument.");
Console.WriteLine (@ "Type ' MyConsole.exe/? ' for usage.");
return false;
}
else
{
if (args[0] = = @ "/?")
{
Console.WriteLine ("The syntax is:");
Console.WriteLine ("MyConsole.exe [Project file]");
Console.WriteLine ();
Console.WriteLine ("[Project file] The path to the XML project file.");
return false;
else
{
string strfilepath = Args[0];
if (file.exists (strFilePath))
{
...
return true;
else
{
Console.WriteLine ("Can not find" specified project file: ' "+ args[0] +" "); 
  
    Console.WriteLine ("Please check the path of project file and try again.");
return false;
}
}

  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.