Command Line

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey
I have already written a program that has a user interface, but I would like
to add some command line interface too. So if the user run it like:
program.exe paramater1
The program do something, but If not, the program normally run with windows
interface.
I tried Sub Main(args[] ... ) but I don't know how to connect it together.
Jarod
 
Jarod said:
I have already written a program that has a user interface, but I would like
to add some command line interface too. So if the user run it like:
program.exe paramater1
The program do something, but If not, the program normally run with windows
interface.
I tried Sub Main(args[] ... ) but I don't know how to connect it together.

Are you writing in C# or VB.NET? This is a C# group, but Sub Main looks
very much like VB.NET...

Writing something with both a command line interface and a windows
interface is relatively tricky, I believe. I suspect there's a way to
write a console application and then have it "disconnect" from the
console if you're running it in Windows mode, but I don't know how
you'd do the disconnection.

To use command line parameters for your Windows app, just change the
signature of Main from

static void Main()

to

static void Main (string[] args)

and work from there.
 
Are you writing in C# or VB.NET? This is a C# group, but Sub Main looks
very much like VB.NET...

Yeah it was mistake, because I also use a VB.Net.
Writing something with both a command line interface and a windows
interface is relatively tricky, I believe. I suspect there's a way to
write a console application and then have it "disconnect" from the
console if you're running it in Windows mode, but I don't know how
you'd do the disconnection.

To use command line parameters for your Windows app, just change the
signature of Main from

static void Main()

to

static void Main (string[] args)

and work from there.

But I have something like this:
I wrote a Windows form application, and now I need to add some command line
parameter. The problem is, when I use Main(...) the program executes only the
main, no windows form interface starts :( I need the program to execute
Main(...) and then to normaly run the windows up.
Jarod
 
Jarod said:
But I have something like this:
I wrote a Windows form application, and now I need to add some command line
parameter. The problem is, when I use Main(...) the program executes only the
main, no windows form interface starts :( I need the program to execute
Main(...) and then to normaly run the windows up.

You'll already have a Main method, which should include Application.Run
somewhere in it - just put your parameter handling stuff before the
call to Application.Run.
 
Hi,

As Jon's said it's tricky to live in both world, I tried it once, did not
work at the first try and I moved along, the solution I got was to have two
separated programs, one was the command line version, the other the windows
version, all the logic was implemented in a dll that both programs share so
no duplicated code ( only the config class that was copied verbatim )
If you need to go from command to win. app to could create a new process
and exec the win app. It should work fine.


Cheers,
 
Hi,

I'm a little confused, do you need to perform any input/output to the
console?
IF you do , then you have a problem ( see my other post)
IF you dont and all you need is to accept some parameters, perform some
action ( without using in any way the console ) and then create the form you
can do it using a windows app, just change the static void Main( ) to
static void Main( string[] args ) and remember that args[0] is the first
parameter, not the program being executed !!!


cheers,


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation



Jarod said:
Are you writing in C# or VB.NET? This is a C# group, but Sub Main looks
very much like VB.NET...

Yeah it was mistake, because I also use a VB.Net.
Writing something with both a command line interface and a windows
interface is relatively tricky, I believe. I suspect there's a way to
write a console application and then have it "disconnect" from the
console if you're running it in Windows mode, but I don't know how
you'd do the disconnection.

To use command line parameters for your Windows app, just change the
signature of Main from

static void Main()

to

static void Main (string[] args)

and work from there.

But I have something like this:
I wrote a Windows form application, and now I need to add some command line
parameter. The problem is, when I use Main(...) the program executes only the
main, no windows form interface starts :( I need the program to execute
Main(...) and then to normaly run the windows up.
Jarod
 
Back
Top