Home All Groups Group Topic Archive Search About

execution from command line

Author
11 Aug 2006 6:53 PM
Selva Chinnasamy
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.

Author
11 Aug 2006 7:41 PM
Kerry Moorman
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.
>
>
>
Author
11 Aug 2006 8:13 PM
zacks
Kerry Moorman wrote:
> 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.

You can access a Console window from a Windows Forms app?

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.
> >
> >
> >
Author
11 Aug 2006 8:22 PM
Selva Chinnasamy
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.
> >
> >
> >
Author
14 Aug 2006 3:17 AM
Jeffrey Tan[MSFT]
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.
Author
14 Aug 2006 8:25 PM
Selva Chinnasamy
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...
> 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
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.
>