0

Hi I would like to make my self able to maybe define my app into CMD by that I can type program instead of program.exe kind of like how ping works for example.

I also need help with arguments. The point of my app is to send a get request to a local server evaling PHP fetching a result from it so I can easy quick debug things and calculate things ect from CMD.

So for example I have to do.

W:\Users\example>e.exe
echo "example";
.....

example


W:\Users\example>

Tow things with the above are very annoying. I need to enter e.exe and THAN I need to enter the code to eval :-/

How could I make it so I could just do

W:\Users\example>e echo "example";
.....

example


W:\Users\example

I really would like to get this working to make use faster + more simple ! this is a programmers way to calculating math :P

EDIT: Below is the code;

static void Main(string[] args)
{
    WebClient client = new WebClient();
    Console.WriteLine("...");
    string input = Console.ReadLine();
    string php = client.DownloadString("http://192.168.1.50/test.php?exec="+input);
    Console.WriteLine(".....");
    Console.WriteLine("");
    Console.WriteLine(php);
    Console.WriteLine("");
}

I've tried to do "+arg[0] but does nothing at start :?

  • I suggest you to start reading this [Command Line Parameters tutorial](http://msdn.microsoft.com/en-us/library/aa288457%28v=vs.71%29.aspx). If you have to parse several options, you can use a helper library to keep your code simple. Check out [Best way to parse command line arguments in C#](http://stackoverflow.com/questions/491595/best-way-to-parse-command-line-arguments-in-c). – Paolo Moretti Feb 24 '13 at 18:08
  • This does not work in cmd.exe either. Note the /c command line option is has available. Just implement that too. – Hans Passant Feb 24 '13 at 18:35

1 Answers1

0

Don't type ".exe" as you don't need to type it... You may want to put your e.exe some place listed in PATH environment variable (or add path to the executable to the PATH).

Main(string[] args) are arguments passed to your program - use them whatever way you want. Note that they will be split on spaces, so you may need to String.Join them back if you need all arguments as one.

You can also use Environment.CommandLine if you need access to comple not parsed command line.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179