|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
execution from command lineHi I have a Windows application written in VB which has many functions. In
addition it also reads a database and generates a output file. Currently this function is called when ever user clicks the button from UI. But I like to call the function from command line too. app.exe database.mdb should call the function to generate the output file. I have modified my Main() to do this. but I wasn't able to send output to console. I have tried many functions in the Console class, but none was helpful. Any ideas on how to send output (or) error info to the console window. Thanks In Advance. Selva,
You should be able to write to the console with a method such as Console.Writeline. You might need to do a Console.Readline as the last statement to the console window, so the window remains on screen instead of disappearing. Then you can hit Enter to close the window. Kerry Moorman Show quoteHide quote "Selva Chinnasamy" wrote: > Hi I have a Windows application written in VB which has many functions. In > addition it also reads a database and generates a output file. > > Currently this function is called when ever user clicks the button from UI. > But I like to call the function from command line too. > app.exe database.mdb should call the function to generate the output file. > > I have modified my Main() to do this. but I wasn't able to send output to > console. I have tried many functions in the Console class, but none was > helpful. > > Any ideas on how to send output (or) error info to the console window. > > Thanks In Advance. > > > Kerry Moorman wrote:
> Selva, You can access a Console window from a Windows Forms app?> > You should be able to write to the console with a method such as > Console.Writeline. > > You might need to do a Console.Readline as the last statement to the console > window, so the window remains on screen instead of disappearing. Then you can > hit Enter to close the window. Show quoteHide quote > > Kerry Moorman > > > "Selva Chinnasamy" wrote: > > > Hi I have a Windows application written in VB which has many functions. In > > addition it also reads a database and generates a output file. > > > > Currently this function is called when ever user clicks the button from UI. > > But I like to call the function from command line too. > > app.exe database.mdb should call the function to generate the output file. > > > > I have modified my Main() to do this. but I wasn't able to send output to > > console. I have tried many functions in the Console class, but none was > > helpful. > > > > Any ideas on how to send output (or) error info to the console window. > > > > Thanks In Advance. > > > > > > Kerry, I have tried doing that. But nothing gets printed to the console
window. Selva Show quoteHide quote "Kerry Moorman" <KerryMoor***@discussions.microsoft.com> wrote in message news:50D711FF-60EB-46EE-8B06-B1E6AB0FF196@microsoft.com... > Selva, > > You should be able to write to the console with a method such as > Console.Writeline. > > You might need to do a Console.Readline as the last statement to the console > window, so the window remains on screen instead of disappearing. Then you can > hit Enter to close the window. > > Kerry Moorman > > > "Selva Chinnasamy" wrote: > > > Hi I have a Windows application written in VB which has many functions. In > > addition it also reads a database and generates a output file. > > > > Currently this function is called when ever user clicks the button from UI. > > But I like to call the function from command line too. > > app.exe database.mdb should call the function to generate the output file. > > > > I have modified my Main() to do this. but I wasn't able to send output to > > console. I have tried many functions in the Console class, but none was > > helpful. > > > > Any ideas on how to send output (or) error info to the console window. > > > > Thanks In Advance. > > > > > > Hi Selva,
Based on my understanding, your winform application wanted to read input from command line while startup and write some output to the console window. Yes, the winform application will disable the console window by default, so the Console.WriteLine method will not have any effect in winform application. To workaround this problem, you have 2 choices: 1. The simplest way is: after creating the winform project, you may change the project type from "Windows Application" to "Console Application"(in Project setting dialog->General->"Output Type" dropdownlist). This will force the runtime to display a console window follow with the GUI form, and any Console.WriteLine method will be displayed in the window. 2. If you do not want to show the console window while startup, but want to display it on-demand. You'd better p/invoke Win32 Console API AllocConsole and AllocConsole to get this done. AllocConsole API will allocate a new console for the calling process, which Console.WriteLine will be displayed, while FreeConsole() will destroy this console when you do not want it. Below is the working sample code snippet: Imports System.Runtime.InteropServices Public Class Form1 Inherits System.Windows.Forms.Form Public Class Win32 <DllImport("kernel32.dll")> _ Public Shared Function AllocConsole() As [Boolean] End Function <DllImport("kernel32.dll")> _ Public Shared Function FreeConsole() As [Boolean] End Function End Class 'Win32 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Win32.AllocConsole() Console.WriteLine("abc") End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Win32.FreeConsole() End Sub End Class Hope this helps. Best regards, Jeffrey Tan Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Thank You so much Jeff. Thats exactly I am looking for,
Thanks Again. ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> wrote in message Show quoteHide quote news:jXrXvA1vGHA.1992@TK2MSFTNGXA01.phx.gbl... http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif> Hi Selva, > > Based on my understanding, your winform application wanted to read input > from command line while startup and write some output to the console > window. > > Yes, the winform application will disable the console window by default, so > the Console.WriteLine method will not have any effect in winform > application. To workaround this problem, you have 2 choices: > > 1. The simplest way is: after creating the winform project, you may change > the project type from "Windows Application" to "Console Application"(in > Project setting dialog->General->"Output Type" dropdownlist). This will > force the runtime to display a console window follow with the GUI form, and > any Console.WriteLine method will be displayed in the window. > > 2. If you do not want to show the console window while startup, but want to > display it on-demand. You'd better p/invoke Win32 Console API AllocConsole > and AllocConsole to get this done. > > AllocConsole API will allocate a new console for the calling process, which > Console.WriteLine will be displayed, while FreeConsole() will destroy this > console when you do not want it. Below is the working sample code snippet: > > Imports System.Runtime.InteropServices > Public Class Form1 > Inherits System.Windows.Forms.Form > > Public Class Win32 > <DllImport("kernel32.dll")> _ > Public Shared Function AllocConsole() As [Boolean] > End Function > > <DllImport("kernel32.dll")> _ > Public Shared Function FreeConsole() As [Boolean] > End Function > End Class 'Win32 > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button1.Click > Win32.AllocConsole() > Console.WriteLine("abc") > > End Sub > > Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles MyBase.Load > > End Sub > > Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles Button2.Click > Win32.FreeConsole() > End Sub > End Class > > Hope this helps. > > Best regards, > Jeffrey Tan > Microsoft Online Community Support > ================================================== > Get notification to my posts through email? Please refer to > Show quoteHide quote > ications. > > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues > where an initial response from the community or a Microsoft Support > Engineer within 1 business day is acceptable. Please note that each follow > up response may take approximately 2 business days as the support > professional working with you may need further investigation to reach the > most efficient resolution. The offering is not appropriate for situations > that require urgent, real-time or phone-based interactions or complex > project analysis and dump analysis issues. Issues of this nature are best > handled working with a dedicated Microsoft Support Engineer by contacting > Microsoft Customer Support Services (CSS) at > http://msdn.microsoft.com/subscriptions/support/default.aspx. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no rights. >
Can I make my program more efficient ?
My for each loops do not compile - VB 2003 Can anyone help in shortening this loop??? tcpListener.AcceptSocket strange behavior Form2.vb[design] innaccessible ! Problem with CustomTyped casting and type checking Binding an Image to a picturebox Encryption: VB 2005 And SQL Server 2005 Crash -> no finalize VB .Net pound problem - HELP! |
|||||||||||||||||||||||