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