954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

exe command

Here i have a problem please help me.
I had made and console application named "input.csproj".On debug it created "input.exe" and the following line of code i have used.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace input
{
    class Program
    {
        static void Main(string[] args)
        {
            string a=Console.ReadLine();
            Console.WriteLine(a);
            Console.ReadKey();
        }
    }
}

Now the the problem is that i want to use it in "cmd" to give it input.Like...


1. Open the cmd.exe
2. "c:\input.exe" "Someinput"
3. it only display the output which is "someinput".


please tell me what i have to do?I will be very thankful to you.


Thankx in advance....

onlinessp
Junior Poster in Training
80 posts since Apr 2010
Reputation Points: 7
Solved Threads: 0
 

Well when you enter command line arguments they are stored in the args array..

static void Main(string[] args) //"someinput" would be stored in here.
        {
            string a=Console.ReadLine(); //this is wrong..Console.ReadLine() reads input from the user when enter is pressed
            Console.WriteLine(a);
            Console.ReadKey();
        }
static void Main(string[] args)
        {
            foreach (string arg in args)
            {
               Console.WriteLine(arg);
             }
        }


You would be better off using a foreach loop to print each argument to the console. The simple loop above will just cycle through each argument you enter. http://msdn.microsoft.com/en-us/library/ttw7t8t6(v=vs.80).aspx

take a look at that and it explains the foreach loop.

james6754
Junior Poster
188 posts since Dec 2010
Reputation Points: 50
Solved Threads: 15
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: