How to run a class from the command line?

R

Robert Dobson

In Java you can execute a single class from the command line using the
command:

java.exe <classname> [args...]

As long as the class in question has a method declared as "public static
final main( String[] args )"

How might I execute a Visual Basic .Net class from the command line
*without* building it as a separate "console" project?

Thanks.
 
A

Armin Zingler

Robert Dobson said:
In Java you can execute a single class from the command line using
the command:

java.exe <classname> [args...]

As long as the class in question has a method declared as "public
static final main( String[] args )"

How might I execute a Visual Basic .Net class from the command
line *without* building it as a separate "console" project?

You can not "run classes", but you can run an application. The start
procedure is Sub Main. It can either be a WinForms or a Console application.
 
R

Robert Dobson

OK, then how about building a "console application" that executes arbitrary
classes? How would I go about coding up a "dotnet.exe" that takes as a
command line argument the name of another class (assuming to be contained in
an included DLL) that will be executed. How do you instantiate and call
methods on a class that's defined at runtime via a string value? Thanks.

dotnet.exe <class to execute> [args passed to class...]



Armin Zingler said:
Robert Dobson said:
In Java you can execute a single class from the command line using
the command:

java.exe <classname> [args...]

As long as the class in question has a method declared as "public
static final main( String[] args )"

How might I execute a Visual Basic .Net class from the command
line *without* building it as a separate "console" project?

You can not "run classes", but you can run an application. The start
procedure is Sub Main. It can either be a WinForms or a Console application.


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
A

Armin Zingler

Robert Dobson said:
OK, then how about building a "console application" that executes
arbitrary classes? How would I go about coding up a "dotnet.exe"
that takes as a command line argument the name of another class
(assuming to be contained in an included DLL) that will be executed.
How do you instantiate and call methods on a class that's defined at
runtime via a string value? Thanks.

dotnet.exe <class to execute> [args passed to class...]

Why not write a library and reference it to execute code in it?

At runtime or as a user I am actually not interested in the class names -
but:

To get the command line:
- Microsoft.VisualBasic.Interaction.Command
- System.Environment.GetCommandLineArgs
- Shared Sub Main(byval Args() As String)

See also:
System.Activator.CreateInstance

and:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpcondiscoveringtypeinformationatruntime.asp
 
H

Herfried K. Wagner [MVP]

* "Robert Dobson said:
In Java you can execute a single class from the command line using the
command:

java.exe <classname> [args...]

As long as the class in question has a method declared as "public static
final main( String[] args )"

How might I execute a Visual Basic .Net class from the command line
*without* building it as a separate "console" project?

This cannot be done. In fact, including the 'void main' in Java will
provide an entry point too.
 
H

Herfried K. Wagner [MVP]

* "Robert Dobson said:
OK, then how about building a "console application" that executes arbitrary
classes? How would I go about coding up a "dotnet.exe" that takes as a
command line argument the name of another class (assuming to be contained in
an included DLL) that will be executed. How do you instantiate and call
methods on a class that's defined at runtime via a string value? Thanks.

dotnet.exe <class to execute> [args passed to class...]

Have a look at "vbc.exe", this will compile an executable file from the
source code provided in files passed in the command line parameters.
After compilation, you can run the "class" by starting the compiled
executable.
 
J

Jay B. Harlow [MVP - Outlook]

Robert,
I would consider using the classes in System.CodeDom.Compiler to load &
compile your source. Specifically the CodeDomProvider class & ICodeCompiler
interface.

Indirectly you would be using one of:
- Microsoft.VisualBasic.VBCodeProvider
- Microsoft.JScript.JScriptCodeProvider
- Microsoft.CSharp.CSharpCodeProvider
- other code providers for other languages.

This will allow your dotnet.exe to include other languages or any language.
Similar to how wsdl.exe & ASP.NET allows any .NET language! (hint I would
use the same parameters as wsdl.exe & the other .NET sdk tools)

Hope this helps
Jay

Robert Dobson said:
OK, then how about building a "console application" that executes arbitrary
classes? How would I go about coding up a "dotnet.exe" that takes as a
command line argument the name of another class (assuming to be contained in
an included DLL) that will be executed. How do you instantiate and call
methods on a class that's defined at runtime via a string value? Thanks.

dotnet.exe <class to execute> [args passed to class...]



Armin Zingler said:
Robert Dobson said:
In Java you can execute a single class from the command line using
the command:

java.exe <classname> [args...]

As long as the class in question has a method declared as "public
static final main( String[] args )"

How might I execute a Visual Basic .Net class from the command
line *without* building it as a separate "console" project?

You can not "run classes", but you can run an application. The start
procedure is Sub Main. It can either be a WinForms or a Console application.


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top