Hi All,
I am developing an application that needs to run in one of two modes:
1. If No command line param is provided the application should run as
Window form.
2. If command line param is provided the application should run as a
console application.
For this i created a windows application with Main
static void Main(string[] cmdLine)
{
Form1 frm = new Form1();
if(cmdLine.Leng th == 0)
{
frm.InitializeF orm();
Application.Run (frm);
}
else
{
frm.ProcessComm andline(cmdLine );
}
}
Problem i have is "Console.writel ine" does not work while running the
application as console ie running the application with params.
Pls help
thanks in advance
regards
Max 6 3333
You will probably have to redirect the output of the Console using the
Console.SetOut and Console.OpenSta ndardOutput method (check the docs for this
method).
HTH, Jakob.
"Max" wrote: Hi All,
I am developing an application that needs to run in one of two modes: 1. If No command line param is provided the application should run as Window form. 2. If command line param is provided the application should run as a console application.
For this i created a windows application with Main
static void Main(string[] cmdLine) { Form1 frm = new Form1(); if(cmdLine.Leng th == 0) { frm.InitializeF orm(); Application.Run (frm); } else { frm.ProcessComm andline(cmdLine ); } }
Problem i have is "Console.writel ine" does not work while running the application as console ie running the application with params.
Pls help
thanks in advance
regards
Max
Max,
[DllImport("kern el32.dll")]
public static extern bool AllocConsole();
[DllImport("kern el32.dll")]
public static extern bool FreeConsole();
public static void Main(string[] args)
{
if (args.Length > 0)
{
AllocConsole();
try
{
// Place console version of code here.
}
finally
{
FreeConsole();
}
}
else
{
// Place windows version of code here.
}
}
There's also an AttachConsole API that you might want to play around
with.
Brian
Max wrote: Hi All,
I am developing an application that needs to run in one of two modes: 1. If No command line param is provided the application should run as Window form. 2. If command line param is provided the application should run as a console application.
For this i created a windows application with Main
static void Main(string[] cmdLine) { Form1 frm = new Form1(); if(cmdLine.Leng th == 0) { frm.InitializeF orm(); Application.Run (frm); } else { frm.ProcessComm andline(cmdLine ); } }
Problem i have is "Console.writel ine" does not work while running the application as console ie running the application with params.
Pls help
thanks in advance
regards
Max
What type of project did you create? Try creating a console
application and then add a reference to the System.Windows. Forms.dll.
You can then use code like this: (vb.Net)
Sub Main(ByVal args() As String)
If args.Length > 0 Then
Console.WriteLi ne("Started with command line args")
Else
Application.Run (New Form1)
End If
End Sub
Worked ok for me.
Chris,
That works too. The only problem I have with this approach is that a
console window is always created. It may not be a big deal for the OP
though. In that case it is certainly easier than using console APIs.
Brian
Chris Dunaway wrote: What type of project did you create? Try creating a console application and then add a reference to the System.Windows. Forms.dll.
You can then use code like this: (vb.Net)
Sub Main(ByVal args() As String)
If args.Length > 0 Then Console.WriteLi ne("Started with command line args") Else Application.Run (New Form1) End If
End Sub
Worked ok for me.
Brain,
I did exactly the same, but while running the application under cmd in
XP,
a new console window fashes. ie. a console window gets created and
exits without displaying any messages.
And i tried what Chris suggested, as you said a console window gets
created when running the app without any arguments.
Any more suggesions.
Max
"Brian Gideon" <br*********@ya hoo.com> wrote in message news:<11******* *************** @o13g2000cwo.go oglegroups.com> ... Max,
[DllImport("kern el32.dll")] public static extern bool AllocConsole();
[DllImport("kern el32.dll")] public static extern bool FreeConsole();
public static void Main(string[] args) { if (args.Length > 0) { AllocConsole(); try { // Place console version of code here. } finally { FreeConsole(); } } else { // Place windows version of code here. } }
There's also an AttachConsole API that you might want to play around with.
Brian
Max wrote: Hi All,
I am developing an application that needs to run in one of two modes: 1. If No command line param is provided the application should run as Window form. 2. If command line param is provided the application should run as a console application.
For this i created a windows application with Main
static void Main(string[] cmdLine) { Form1 frm = new Form1(); if(cmdLine.Leng th == 0) { frm.InitializeF orm(); Application.Run (frm); } else { frm.ProcessComm andline(cmdLine ); } }
Problem i have is "Console.writel ine" does not work while running the application as console ie running the application with params.
Pls help
thanks in advance
regards
Max
Max,
Make sure the project output type is "Windows Application". If you run
the application in the debugger it will create a new console window,
but the standard output is redirected to the output window in the IDE
and not the new console window. Look there for the output. If you run
the application from cmd it will create a new console and send the
standard output there. Be sure to put a Console.ReadLin e call at the
end so that you have time to read the output. If you want the standard
output to go the command prompt directly you may have to use the
AttachConsole API. I haven't experimented around with that yet.
Brian
Max wrote: Brain,
I did exactly the same, but while running the application under cmd in XP, a new console window fashes. ie. a console window gets created and exits without displaying any messages.
And i tried what Chris suggested, as you said a console window gets created when running the app without any arguments.
Any more suggesions.
Max This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dom |
last post by:
can someone please help me display text in the console
cout << "Testing";
in a different colour to the default one
|
by: Max |
last post by:
Hi All,
I am developing an application that needs to run in one of two modes:
1. If No command line param is provided the application should run as
Window form.
2. If command line param is provided the application should run as a
console application.
For this i created a windows application with Main
|
by: Mark Allison |
last post by:
Hi,
I have an application that I want to be to run in Console mode and GUI
mode. If no params are entered, I want the GUI fired up, if params are
entered, then go into console mode.
I believe I have all the code set up to do this, however when I issue a
Console.WriteLine instruction, nothing gets written to the console. In
fact, the command prompt comes back before the program has finished
executing. What do I need to do?
|
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
|
by: Jarod_24 |
last post by:
I got a project called "Forms" that hold some forms and stuff in my
solution.
A argument at startup defines wether to use a From or Console.
My plan was to create a myConsole class that would also allow my application
to display a Console, but i don't seem to be allowed to do this.
I don't see any References that i need to add, so how do i do this.
| |
by: Alison |
last post by:
Hi, Al
I am trying to design a user interface which provides both menus and toolbars for some users to click on whatever they want to do, at the same time, I would like to have a console window available in the same form for users to enter commands and display outputs if some prefer to use character based user interface. I would like to implement the user interface in vb .net. Now I have menus and toolbars ready, but do not now how to get a...
|
by: Kevin |
last post by:
In a newsgroup thread from Jan 8, 2003 between Barry Holsinger and the
VBDotNet Team, please review this excerpt:
"You understood my problem completely. Your sample code provides a
really
elegant way to inject CrLf into the input stream, which effectively
unblocks
the ReadLine method. Last night, I had finally got the
WriteConsoleInput
|
by: Ant |
last post by:
Hi all,
I'm putting together a simple help module for my applications, using
html files stored in the application directory somewhere. Basically it
sets up a basic web server, and then uses the webbrowser module to
display it in the users browser. I have it set up to call sys.exit(0)
if the url quit.html is called, but for some reason (on Windows XP via
the cmd.exe shell) python won't let me have the console back. I get the
System Exit...
|
by: SriBhargav |
last post by:
Hi,
I've a question on setting timeout on console.readline()
I would like the user to input something through Console.readline() in
5 secs. If there is no input in that time, I would like to proceed
further with the program logic.
I had a difficulty in implementing this, as console.readline()
indefinitely waits for the user input.
|
by: Dilip |
last post by:
Hi All
I have a server based C# console application. This application must
hide its console window when its launched out on the field. So I
dutifully P/Invoke'd FindWindow/ShowWindow combination to hide the
console window at launch time.
The application (for legacy reasons) hangs around by waiting on an old-
fashioned Console.ReadLine() statement.
|
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...
| |
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |