473,729 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GUI and Console Apps

Hi I have a really basic question hopefully some can help me with:

Can you write a (i.e. one) C# project that works from the cmd line and gui?

I seems if i write a GUI app it can't write to console using
System.Console. WriteLine if thge project has its "Output Type" to
"Windows Application".

However I can write to stdio if i set output type to "Console
Application". When I do this I unfortunately get a "console box" as well
as the UI when i start the UI without command line instructions.

Cheers,
JIm
Nov 17 '05 #1
17 4232


Surely if you want to write to the console then you'd want to see the
console box as you want to write to it?

or do you only want to see the console when it's run from cmd? (in which
case, compile as GUI, run from cmd)

I think I'm not understanding what you want.... can you explain more?

"MumboJumbo " wrote:
Hi I have a really basic question hopefully some can help me with:

Can you write a (i.e. one) C# project that works from the cmd line and gui?

I seems if i write a GUI app it can't write to console using
System.Console. WriteLine if thge project has its "Output Type" to
"Windows Application".

However I can write to stdio if i set output type to "Console
Application". When I do this I unfortunately get a "console box" as well
as the UI when i start the UI without command line instructions.

Cheers,
JIm

Nov 17 '05 #2


Surely if you want to write to the console then you'd want to see the
console box as you want to write to it?

or do you only want to see the console when it's run from cmd? (in which
case, compile as GUI, run from cmd)

I think I'm not understanding what you want.... can you explain more?

"MumboJumbo " wrote:
Hi I have a really basic question hopefully some can help me with:

Can you write a (i.e. one) C# project that works from the cmd line and gui?

I seems if i write a GUI app it can't write to console using
System.Console. WriteLine if thge project has its "Output Type" to
"Windows Application".

However I can write to stdio if i set output type to "Console
Application". When I do this I unfortunately get a "console box" as well
as the UI when i start the UI without command line instructions.

Cheers,
JIm

Nov 17 '05 #3
I want an app that will do this:

cmd.exe ... start the gui with a new workspace
cmd.exe file.xml ... start the gui with file.xml

But when a certain group of extra args are used it will run as a console
app ... -applytransform junk.xlst file.xml ... etc ...
Jim

Chris Walters wrote:

Surely if you want to write to the console then you'd want to see the
console box as you want to write to it?

or do you only want to see the console when it's run from cmd? (in which
case, compile as GUI, run from cmd)

I think I'm not understanding what you want.... can you explain more?

"MumboJumbo " wrote:

Hi I have a really basic question hopefully some can help me with:

Can you write a (i.e. one) C# project that works from the cmd line and gui?

I seems if i write a GUI app it can't write to console using
System.Consol e.WriteLine if thge project has its "Output Type" to
"Windows Application".

However I can write to stdio if i set output type to "Console
Application ". When I do this I unfortunately get a "console box" as well
as the UI when i start the UI without command line instructions.

Cheers,
JIm

Nov 17 '05 #4
"or do you only want to see the console when it's run from cmd? (in which
case, compile as GUI, run from cmd)"

Sorry, thats clearly not true - what was I thinking!

I think my question back to you is; Why do you want to write to the console
when the application is a GUI?

If for debugging only --> System.Console writes to the output window of
Visual Studio, so you'll see it when developing / debugging etc.

If for other reasons, maybe write to a log file on disk? Maybe only create
the log file when the App.config has a "log=on" flag set - allow it to be
turned on / off ?

Nov 17 '05 #5
I want an app that will do this:

cmd.exe ... start the gui with a new workspace
cmd.exe file.xml ... start the gui with file.xml

But when a certain group of extra args are used it will run as a console
app ... -applytransform junk.xlst file.xml ... etc ...
Jim

Chris Walters wrote:

Surely if you want to write to the console then you'd want to see the
console box as you want to write to it?

or do you only want to see the console when it's run from cmd? (in which
case, compile as GUI, run from cmd)

I think I'm not understanding what you want.... can you explain more?

"MumboJumbo " wrote:

Hi I have a really basic question hopefully some can help me with:

Can you write a (i.e. one) C# project that works from the cmd line and gui?

I seems if i write a GUI app it can't write to console using
System.Consol e.WriteLine if thge project has its "Output Type" to
"Windows Application".

However I can write to stdio if i set output type to "Console
Application ". When I do this I unfortunately get a "console box" as well
as the UI when i start the UI without command line instructions.

Cheers,
JIm

Nov 17 '05 #6
"or do you only want to see the console when it's run from cmd? (in which
case, compile as GUI, run from cmd)"

Sorry, thats clearly not true - what was I thinking!

I think my question back to you is; Why do you want to write to the console
when the application is a GUI?

If for debugging only --> System.Console writes to the output window of
Visual Studio, so you'll see it when developing / debugging etc.

If for other reasons, maybe write to a log file on disk? Maybe only create
the log file when the App.config has a "log=on" flag set - allow it to be
turned on / off ?

Nov 17 '05 #7
Compile as GUI --> you can still start it from the command line.

make your main like this:

static void Main(string[] args) {
//do argument "magic" here:
if (args!=null){
string firstParameter = args[0];
}
}

--> Check this for some nice code to pull out your parameters:
http://www.codeproject.com/csharp/Cp...ineEmailer.asp
//take a look at Main and CommandLinePars er(string sCommandLine)

Assuming you don't want to run in a batch environment - I'd personally not
bother with the command line parameters, and use the App.config to push
parameters into the application. If you are running in batch - don't do a GUI
!

If the parameters change frequently, maybe have the ability to store them in
a file somewhere and then read that file in.

If you want to kick it off from the command line and then have it auto kill
the "black window" - I'm not sure this is possible....

Check out using App.config and look into
System.Configur ation.Configura tionSettings.Ap pSettings
Nov 17 '05 #8
Compile as GUI --> you can still start it from the command line.

make your main like this:

static void Main(string[] args) {
//do argument "magic" here:
if (args!=null){
string firstParameter = args[0];
}
}

--> Check this for some nice code to pull out your parameters:
http://www.codeproject.com/csharp/Cp...ineEmailer.asp
//take a look at Main and CommandLinePars er(string sCommandLine)

Assuming you don't want to run in a batch environment - I'd personally not
bother with the command line parameters, and use the App.config to push
parameters into the application. If you are running in batch - don't do a GUI
!

If the parameters change frequently, maybe have the ability to store them in
a file somewhere and then read that file in.

If you want to kick it off from the command line and then have it auto kill
the "black window" - I'm not sure this is possible....

Check out using App.config and look into
System.Configur ation.Configura tionSettings.Ap pSettings
Nov 17 '05 #9
A common pattern to achieve this is:
- Create two apps. One gui and one console by the same name and put them in
the same directory.
- Name the console version *.com and the gui *.exe. The .com will be found
first in the normal search order so you console app will start first.
- Your console app will parse the command line. If console args, the app
continues as your normal.
- If args dictate GUI args, you Process start the *.exe command in same dir
passing in the args.

This will allow your console version to use the parent console as you would
expect (i.e. no new console). And will also allow you to start the GUI
version based on args and leave the current console intact. A desktop icon
or start menu would point the exe version if you wanted gui. From console
you could also specify *.exe if you wanted direct access to the gui version.
hth

--
William Stacey [MVP]

"MumboJumbo " <ju**@junk.be > wrote in message
news:Xa******** ***********@new s20.bellglobal. com...
Hi I have a really basic question hopefully some can help me with:

Can you write a (i.e. one) C# project that works from the cmd line and
gui?

I seems if i write a GUI app it can't write to console using
System.Console. WriteLine if thge project has its "Output Type" to "Windows
Application".

However I can write to stdio if i set output type to "Console
Application". When I do this I unfortunately get a "console box" as well
as the UI when i start the UI without command line instructions.

Cheers,
JIm

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1988
by: Ken VdB | last post by:
Hi everyone, One of the things that really interested me about VS.net was that I can now create a console based app using VB. I have a number of QuickBASIC 4.5 apps which we are still using and for which I still have source code. I would love to port these to VB.net but can't figure out how to print to the screen. I suddenly realized it has been a long time since I have done anything like this (most of my apps are web-based with a...
5
11254
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
6
5961
by: MeowCow | last post by:
I will try and make my question with out being too long winded. I have been doing a lot of reading on how to do multithreading and I have implemented the code from the following example on codeproject and msdn. http://www.codeproject.com/csharp/LaunchProcess.asp http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/default.aspx In the eample Standard out is read like this:
7
4201
by: Robert | last post by:
Hello, I'm using Pythonwin and py2.3 (py2.4). I did not come clear with this: I want to use win32-fuctions like win32ui.MessageBox, listctrl.InsertItem ..... to get unicode strings on the screen - best results according to the platform/language settings (mainly XP Home, W2K, ...). Also unicode strings should be displayed as nice as possible at the console with normal print-s to stdout (on varying platforms, different
5
8387
by: Jon Davis | last post by:
Is there such a thing as a Windows standard for killing a console app that is monitored by a System.Diagnostics.Process object? I'm hosting several C# console apps in a C# Windows service and would like to standardize on a graceful termination method when the Windows service stops. Jon
0
1383
by: serpius | last post by:
Hello Everyone, I am a beginner in VB.Net 2003 and am taking classes in beginning VB.net. To make a long story short, I am looking for real samples of coding in Console Apps. I am the type of person that learns more by seeing samples of actual coding than what the teacher verbalizes in class. Besides, this teacher is not all that great to begin with, but the class is stuck with him. The teacher is starting us out in creating apps in...
4
1453
by: Paul Hemans | last post by:
Hi newbie here. I am learning c++/cli I by writing console apps. When my apps finished they used to display a message at the bottom of the screen, something like "press any key to continue" so that you could see the results before returning to the IDE. But now they don't. I must have turned a setting off somewhere but I can't find it. I could code it in but I would prefer not to. Any ideas?
3
10112
by: Alex | last post by:
Hello, I'm wroting a console utility in VB 2005, and I need the ability to pass parameters to the application when the program runs. For example, if my program is called testing.exe, I need to be able to run this: c:\testing.exe c:\test ....and have 'c:\test' passed to the program as a variable. Most of my VB books focus on web forms or windows forms, but not much details on console
5
3022
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I'm learning C# via console apps (to avoid getting bogged down in Windows stuff). I'm wondering how the OO paradigm would work. Say I'm developing 'classic' menu-driven apps where a menu gives a number of options, you choose an option and then do something. Traditionally I would set up a loop - waiting for the Exit option - and, say, create database records, update them or delete them. This would make my Main() look a bit 'procedural',...
0
8925
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8763
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9288
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9154
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4797
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2692
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2166
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.