Showing posts with label command line. Show all posts
Showing posts with label command line. Show all posts

Sunday, December 12, 2010

Command Line parameters - Eclipse

  • In Eclipse beside the "Run" button there is a downward arrow. Click on it.
  • In the drop-down menu click on "Run Configurations".
  • It will open a new window "Run Configurations", there select the required project.



  • Goto "Arguments" tab and inside "Program arguments" text area type command-line parameters separated by a space.


Dealing with external jar files on command prompt

I had a problem with compiling and running a java file in command line where it imports an external jar files. Here is the solution I've found.

Compilation

javac -cp <path to where the source codes resides>;<path to where the jar file resides> Example.java

run

java <path to where the source codes resides>;<path to where the jar file resides> Example <command-line arguments if any>

Note 1:  separator ; for windows and : for unix
Note 2:  multiple jar files can be used delimited by ;
Note 3:  . can be used to specify the current directory

Sunday, December 5, 2010

Command Line Parameters C#

Following code shows how command line parameters can accessed in C#.

//CommandLine3.cs
// Commandline arguments: A B C
using System;

namespace CommandLine3
{             
        public class CommandLine3
        {
            public static void Main(string[] args)
            {
                Console.WriteLine("You have entered the following {0} command line arguments:",args.Length);
                for (int i = 0; i < args.Length; i++)
                {
                    Console.WriteLine("{0}", args[i]);
                }
                Console.ReadLine();
            }
        } 
}

Note that:
  • The Length property is used to obtain the length of the array.
  • Length is a read-only property
Following expanation will be a guide on building and running the code within Visual Studio.
  • Right-click the project(in the above example CommandLine3 will be the project) and click Properties this will open up Open the configuration Properties window and click Debugging tab.





  • In the Command Line Arguments property, type "A B C" and save the project





  • Run the project, make sure project has set as the startup project(to do this right click on the project and click on set as startup project

For running the code using command-line use following commands
  • csc CommandLine.cs
  • CommandLine.exe A B C

output


references : http://msdn.microsoft.com/