473,405 Members | 2,379 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Writing to the console from a GUI application

I have a GUI application that needs to be invoked from the command line
as well. It should work both as a GUI and as a console application.

When I invoke it from the command line, it reads all the command line
options perfectly. However, I can't use Console.WriteLine to write
messages to the console (the lines don't appear at the console window).

Is it possible? What should I do to "connect" the console?

My Main() is:

static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new WorkspaceForm());
return;
}
if (args.Length == 2 && args[0].ToLower() == "-mycommand")
{
DoMyCommand(args[1]);
return;
}
Console.WriteLine("Usage:\n\napplication_name -mycommand
<file>\n");
Console.WriteLine(" Performs mycommand on file.\n");
}
Thanks
Eduardo

Jun 6 '06 #1
4 8588
Hello ed********@gmail.com,

You need to use API function AllocConsole
See samlpe of usin it in C# there http://groups.google.com/group/micro...2ca7a3ebfde2df
I have a GUI application that needs to be invoked from the command
line as well. It should work both as a GUI and as a console
application.

When I invoke it from the command line, it reads all the command line
options perfectly. However, I can't use Console.WriteLine to write
messages to the console (the lines don't appear at the console
window).

Is it possible? What should I do to "connect" the console?

My Main() is:

static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new WorkspaceForm());
return;
}
if (args.Length == 2 && args[0].ToLower() == "-mycommand")
{
DoMyCommand(args[1]);
return;
}
Console.WriteLine("Usage:\n\napplication_name -mycommand
<file>\n");
Console.WriteLine(" Performs mycommand on file.\n");
}
Thanks
Eduardo

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jun 6 '06 #2
The code looks fine, it doesn't write the usage statement out if you
pass the incorrect parameters?

ed********@gmail.com wrote:
I have a GUI application that needs to be invoked from the command line
as well. It should work both as a GUI and as a console application.

When I invoke it from the command line, it reads all the command line
options perfectly. However, I can't use Console.WriteLine to write
messages to the console (the lines don't appear at the console window).

Is it possible? What should I do to "connect" the console?

My Main() is:

static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new WorkspaceForm());
return;
}
if (args.Length == 2 && args[0].ToLower() == "-mycommand")
{
DoMyCommand(args[1]);
return;
}
Console.WriteLine("Usage:\n\napplication_name -mycommand
<file>\n");
Console.WriteLine(" Performs mycommand on file.\n");
}
Thanks
Eduardo


Jun 6 '06 #3
Why would he need to use AllocConsole? He wants to write to the console
from which his application was invoked

Michael Nemtsev wrote:
Hello ed********@gmail.com,

You need to use API function AllocConsole
See samlpe of usin it in C# there http://groups.google.com/group/micro...2ca7a3ebfde2df
I have a GUI application that needs to be invoked from the command
line as well. It should work both as a GUI and as a console
application.

When I invoke it from the command line, it reads all the command line
options perfectly. However, I can't use Console.WriteLine to write
messages to the console (the lines don't appear at the console
window).

Is it possible? What should I do to "connect" the console?

My Main() is:

static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new WorkspaceForm());
return;
}
if (args.Length == 2 && args[0].ToLower() == "-mycommand")
{
DoMyCommand(args[1]);
return;
}
Console.WriteLine("Usage:\n\napplication_name -mycommand
<file>\n");
Console.WriteLine(" Performs mycommand on file.\n");
}
Thanks
Eduardo

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


Jun 6 '06 #4
Yes, I want to write to the console where the user typed the
application name and parameters.

It doesn't show the usage lines.

I've found some more info about this, and nobody seems to have a
solution.

One solution implies changing the aplication to a console application,
and releasing the console if it should be run in GUI mode, which will
flash a black window. Another implies creating two applications with
the same name, but one with .EXE and one with .COM extensions. Both are
very bad...

It's hard to accept that "computers can't do this", isn't it? It's
something so simple.

Maybe it's a question of getting the handlers for STDIN and STDOUT and
passing them to Console.In and Console.Out?...

Eduardo

sd********@gmail.com wrote:
Why would he need to use AllocConsole? He wants to write to the console
from which his application was invoked

Michael Nemtsev wrote:
Hello ed********@gmail.com,

You need to use API function AllocConsole
See samlpe of usin it in C# there http://groups.google.com/group/micro...2ca7a3ebfde2df
I have a GUI application that needs to be invoked from the command
line as well. It should work both as a GUI and as a console
application.

When I invoke it from the command line, it reads all the command line
options perfectly. However, I can't use Console.WriteLine to write
messages to the console (the lines don't appear at the console
window).

Is it possible? What should I do to "connect" the console?

My Main() is:

static void Main(string[] args)
{
if (args.Length == 0)
{
Application.Run(new WorkspaceForm());
return;
}
if (args.Length == 2 && args[0].ToLower() == "-mycommand")
{
DoMyCommand(args[1]);
return;
}
Console.WriteLine("Usage:\n\napplication_name -mycommand
<file>\n");
Console.WriteLine(" Performs mycommand on file.\n");
}
Thanks
Eduardo

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche


Jun 6 '06 #5

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

Similar topics

3
by: Raaijmakers, Vincent (IndSys, GE Interlogix) | last post by:
Ok, perhaps a question on a newbie level. I try to create a simple 'write to a console application' where all the items in a string do have a variable size: items = Well, actually, I need to...
3
by: Marius Rus | last post by:
I have a project in C# that do the followings: From an csv text file it is taking datas and inserted into an paradox database. My problem it is that when writing into the paradox database it is...
7
by: mahendranepali | last post by:
I am making a simulator application that will simulate different concurrent users connecting to a database. the application creates different userkeys and pushes them to the database tables. The...
2
by: John Salerno | last post by:
I wrote this code just to experiment with writing to and reading from a file. It seems to work fine when writing, but when reading the file, it only prints the filepath to the screen, not the file...
1
by: Falo | last post by:
I've seen GUIs for console applications where the console window is hidden. How is this done, and how is the GUI app "tied" to the console app? That is, I know how to pass commands to an app at...
2
by: Oenone | last post by:
I'm writing an application that I'd like to be able to use both as a Windows Forms application, and also as a Console application. If the app is started with no parameters, it should display its...
5
by: Mark M | last post by:
I am attempting to use a third party command-line utility (WinDump.exe) to capture network traffic for perfromance analysis. This utility when launched captures network traffic until Ctrl-C is...
1
by: Smita Prathyusha | last post by:
I am facing a problem in writing to COM1. I am using a Win 32 Console mode Program in VC++ the following is the code: If anyone can help me out it will be of great help : // SC_Using_Classes.cpp...
6
by: Peted | last post by:
Hi, im wanting to store some custom text strings in the app.config file of a c# app, to be retreived and updated when the app runs. using c# 2005 express in my testing i am using the code...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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...

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.