473,407 Members | 2,306 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,407 software developers and data experts.

execution from command line

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.
Aug 11 '06 #1
5 1503
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.
Aug 11 '06 #2

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?
>
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.

Aug 11 '06 #3
Kerry, I have tried doing that. But nothing gets printed to the console
window.

Selva

"Kerry Moorman" <Ke**********@discussions.microsoft.comwrote in message
news:50**********************************@microsof t.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.


Aug 11 '06 #4
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 14 '06 #5
Thank You so much Jeff. Thats exactly I am looking for,

Thanks Again.

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:jX**************@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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
>

Aug 14 '06 #6

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

Similar topics

75
by: Beni | last post by:
I have been programming in C for about a year now. It sounds silly, but I never took the time to question why a C(or C++ or Java) program execution begins only at the main(). Is it a convention or...
4
by: Hari | last post by:
From: "Hari" <harixseshadri@yahoo.com> Subject: .exe file execution Date: Friday, August 13, 2004 2:42 PM In VB.NET, the output is a .exe file. Since I am new at VB, I am still only programming...
1
by: brianbasquille | last post by:
Hello all, Hope you can help me with this little conundrum! I'm running a batch file and want to print the execution of it line-by-line. Best reference i could find was:...
17
by: blufox | last post by:
Hi All, Can i change the execution path of methods in my process at runtime? e.g a()->b()->c()->d()->e() Now, i want execution to be altered at runtime as -
5
by: pauldepstein | last post by:
Is there any standard c++ command for halting execution? The nearest equivalent I can find is assert(false); However this only works in debug mode. I'm trying to examine the execution flow of...
4
by: Michel Esber | last post by:
Environment: DB2 v8 LUW FP 15 running on Linux. For some reason that I can´t explain, a simple insert statement on a table may run very quickly, or may take forever (20-30mins) to finish....
2
by: Ralf Seliger | last post by:
Hi, I hope someone here has a clue as to what is going on since I am completely baffled by the following: I'm working with a PHP/MySQL-web application called Moodle. When this application is...
6
by: xhe | last post by:
I am using ffmpeg to convert video, this is a sample script: $str='/home/transla1/bin/ffmpeg -i /home/transla1/public_html/ cybertube/web/uploads/video/31_AK000005.AVI -s 240x180 -b 100k -ar...
5
by: Guillermo Antonio Amaral Bastidas | last post by:
Hi everybody, I have a quick and probably dumb question, keep in mind I just dumped my old love FastCGI + Perl for it's younger hotter friend PHP5. If the user calls a time consuming script...
5
by: dsky | last post by:
I have a program in C#.NET which runs in both GUI and command line mode. When I pass the command line arguments to the executable like: C:\>myprogram.exe -a file.txt the program is invoked,...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
agi2029
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,...

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.