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

Get Result OF Console

Is there any way in .NET to force to run console application through
it and get the result of tht application in our program.

Please reply me quickly.
Any reply will highly be appreciated.
Thanx.
Nov 20 '05 #1
3 1598
Be more specific !

OHM

Mr Mind - Lion wrote:
Is there any way in .NET to force to run console application through
it and get the result of tht application in our program.

Please reply me quickly.
Any reply will highly be appreciated.
Thanx.


--
Best Regards - OHM
one.handed.man{at}BTInternet{dot}com
Nov 20 '05 #2
This may be a little rough, but I've used the code below to launch a console
application and have the output displayed on a VB.NET form called
"fMainForm" in a textbox called "txtLog".

The "WaitForExe" sub routine launches the specified application, and the
"hide" variable determines if the console application will be shown or
hidden. If the application is hidden, the "monitorProc" sub routine is
called to redirect the standard output for the application so that the
VB.NET application can receive all of the information. Otherwise, the main
VB application is hidden until the console app completes.

I used this mainly with "makecab.exe" so that I could display the progress
of the cabinet creation process without having the console application being
seen by the user. Maybe this will give you some idea of how to accomplish
the task....
' Launch a process and wait for it to exit
Public Function WaitForExe(ByVal fileName As String, ByVal args As
String, ByVal wDir As String, Optional ByVal hide As Boolean = True)
Dim startinfo As New ProcessStartInfo()
startinfo.FileName = fileName
If args <> "" Then
startinfo.Arguments = args
End If

If hide Then
startinfo.RedirectStandardOutput = True
startinfo.CreateNoWindow = True
startinfo.UseShellExecute = False
End If

If wDir <> "" Then
startinfo.WorkingDirectory = wDir
End If

Dim myproc As Process = Process.Start(startinfo)

Dim StdOut As IO.StreamReader = Nothing
If hide Then
StdOut = myproc.StandardOutput
End If
Application.DoEvents()
System.Threading.Thread.Sleep(100)
If hide Then
monitorProc(myproc, StdOut)
Else
fMainForm.ShowInTaskbar = False
fMainForm.Hide()
myproc.WaitForExit(Int32.MaxValue)
fMainForm.ShowInTaskbar = True
fMainForm.Show()
End If
End Function

' Monitor a process
Private Function monitorProc(ByVal myproc As Process, ByVal StdOut As
IO.StreamReader)
Dim g As Drawing.Graphics =
Drawing.Graphics.FromHwnd(fMainForm.txtLog.Handle)
Try
Dim iPeek As Integer = StdOut.Peek
While iPeek > 0
Dim cBuff(iPeek) As Char
Dim str As String = StdOut.ReadLine
Dim pos As Integer = str.IndexOf(Chr(13))
While pos > -1
Dim ts As String
If str.Length > pos + 1 Then
ts = str.Substring(0, pos) & vbCrLf &
str.Substring(pos + 1)
Else
ts = str.Substring(0, pos) & vbCrLf
End If
str = ts
If str.Length > pos + 1 Then
pos = str.IndexOf(Chr(13), pos + 1)
Else
pos = -1
End If
End While
g.FillRectangle(Drawing.SystemBrushes.Control, 2,
fMainForm.txtLog.Height - 20, fMainForm.txtLog.Width - 8, 23)
g.DrawString(str, fMainForm.txtLog.Font,
Drawing.SystemBrushes.ControlText, 0, fMainForm.txtLog.Height - 25)
iPeek = StdOut.Peek
End While
g.FillRectangle(Drawing.SystemBrushes.Control, 2,
fMainForm.txtLog.Height - 20, fMainForm.txtLog.Width - 8, 23)
Catch exc As Exception
Debug.WriteLine(exc.Message)
End Try
End Function

"Mr Mind - Lion" <Mr*******@Hotmail.com> wrote in message
news:e0*************************@posting.google.co m...
Is there any way in .NET to force to run console application through
it and get the result of tht application in our program.

Please reply me quickly.
Any reply will highly be appreciated.
Thanx.

Nov 20 '05 #3
* Mr*******@Hotmail.com (Mr Mind - Lion) scripsit:
Is there any way in .NET to force to run console application through
it and get the result of tht application in our program.


<http://www.mvps.org/dotnet/dotnet/samples/miscsamples/downloads/RedirectConsole.zip>

--
Herfried K. Wagner [MVP]
<http://dotnet.mvps.org/>
Website Address Changed!
Nov 20 '05 #4

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

Similar topics

5
by: Drew Yallop | last post by:
I read an XML file with a stream reader in VB.Net. When I look at the stream reader output in debug mode (by passing cursor over the stream reader object)the format is a perfect replica of the...
7
by: dlarock | last post by:
I wrote the following to do an MD5 hash. However, I have a problem (I think) with the conversion from the Byte MD5 hash back to string. Watching this through the debugger it appears as if the...
5
by: kelmen | last post by:
Try the below simple program. It give expected result. 1 1 2 2 Then toggle the statements in private static int sinc(), to use Test._num ++ .
2
by: fineman | last post by:
Hi all, I want to get a 64bit(8 bytes) Encrypt result use DES class in the VS2005. Though I encrypt data is 64bit(8 bytes), but DES return encrypt result that always is 128bit(16 bytes), I don't...
10
by: Tony K | last post by:
How would I assign the result of a SQL query to a variable. The result of the following statement will ALWAYS result in 1 row returned. SELECT ProductDescription, ProductID FROM ...
17
by: Paul van Brouwershaven | last post by:
I have some problems with the curl. On the console I get the right response message but in PHP I see no difference between a valid and an invalid SSL Certificate. Curl command in PHP: $url =...
11
by: Peter Holschbach | last post by:
Hi, I've the following line of code: result = DateTime.ParseExact("1999-12-01T23:59:59Z", "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture); where I get in result "result" "02.12.1999...
2
by: GD | last post by:
I am trying to execute a third party console application and return the result dispalayed in the console screen. Can this be achieved? Thanks. GD
9
by: Elroy Flynn | last post by:
Decimal a = 42.485M; Decimal b = 48M; Decimal c = a / b; Console.WriteLine(c.ToString()); gives the result 0.8851041666666666666666666667 The correct, exact answer is .885. I know that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.