Three ways to have a WPF form program support command-line operations

Source: Internet
Author: User
Tags command line

Sometimes we want the form program to accept command-line arguments and run it as a console. But it takes a little skill to make it happen. If you are doing a WPF program, write such a statement in the loaded event of window:

Console.WriteLine ("Hello word.");

Then run it from CMD. You will find that the statement has no output at all. As shown in Figure 1.

Figure 1. To run a WPF program from the command line

There are three solutions for this problem. Each of the three programmes has advantages and disadvantages and should be chosen as appropriate.

1. Use the more command: This scenario does not require any modification of the code, as long as you run it from the command line, add a "| More "can. As shown in Figure 2.

Figure 2. Use more redirect output

2. Change the output Type of the program: in the VS menu, locate project-> [Project Name] Properties ..., select the Application tab. Change the output Type from Windows application to the console application. The consequence is that there is a console window that comes with the main form, whether it is running from the command line or not. As shown in Figure 3.

Figure 3. Effect of converting Output type to console application

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.