using System;
using System.Diagnostics;
namespace Command_Line_Arguments
{
class Class1
{
static void Main(string[] args)
{
int i = 0;
foreach (string str in args)
{
Console.WriteLine(args[i++]);
}
Process proc = new Process ();
switch(args[0])
{
case "notepad" :
proc.StartInfo.FileName = @"Notepad.exe";
// you can write any file name or remove the argument
proc.StartInfo.Arguments = "c:\\temp.txt";
// proc.StartInfo.Arguments = args[1];
proc.Start();
break;
case "calculator" :
proc.StartInfo.FileName = @"Calc.exe";
proc.StartInfo.Arguments = "";
proc.Start();
break;
case "fexplorer" :
proc.StartInfo.FileName = @"explorer.exe";
proc.StartInfo.Arguments = "";
proc.Start();
break;
default: Console.WriteLine("Arguments Error");
break;
}
}
}
}
// use this program like this:
// Command_Line_Arguments.exe calculator
// Command_Line_Arguments.exe fexplorer
// Command_Line_Arguments.exe notepad c:\temp.txt