473,554 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Diagnost ics.Process

Hello All,

Hopefully someone has run into this error. I have written a class(source
below) that launches a thread to monitor the StandardOutput of a
System.Diagnost ics.Process, in particular I am executing the find.exe
program.

The application works perfectly in the development environment. As soon as
I execute the compiled program and start the find process I get an
"Applicatio n Error". The error states that the instruction 0x7552bb73
referenced memory at "0x00000000 0" the memor could not be read.

Has anyone seen this behavior? If so can you point me in the write direction
to a solution?

Thanks,
Dan

Imports System
Imports System.Collecti ons.Specialized
Imports System.Diagnost ics
Imports System.IO
Imports System.Threadin g
Friend Class ProcessControll er
Private mobjStartInfo As ProcessStartInf o
Private WithEvents mobjProcess As System.Diagnost ics.Process
Private mobjErrorMonito r As System.Threadin g.Thread
Private mobjOutputMonit or As System.Threadin g.Thread
Public Sub New(ByVal startInfo As ProcessStartInf o)
Me.mobjStartInf o = startInfo
End Sub
Public Sub New(ByVal filename As String, ByVal arguments As String, ByVal
environmentVari ables As StringDictionar y)
Dim fileInfo As System.IO.FileI nfo
fileInfo = New System.IO.FileI nfo(filename)
mobjStartInfo = New ProcessStartInf o
mobjStartInfo.F ileName = fileInfo.FullNa me
mobjStartInfo.W orkingDirectory = fileInfo.Direct oryName
mobjStartInfo.A rguments = arguments
If Not (environmentVar iables Is Nothing) Then
For Each var As String In environmentVari ables.Keys
If (mobjStartInfo. EnvironmentVari ables.ContainsK ey(var)) Then
mobjStartInfo.E nvironmentVaria bles(var) = environmentVari ables(var)
Else
mobjStartInfo.E nvironmentVaria bles.Add(var, environmentVari ables(var))
End If
Next
End If
mobjStartInfo.R edirectStandard Output = True
mobjStartInfo.R edirectStandard Error = True
mobjStartInfo.R edirectStandard Input = True
mobjStartInfo.U seShellExecute = False
End Sub
Public ReadOnly Property MyProcess() As Process
Get
Return (Me.mobjProcess )
End Get
End Property
Public Function Start() As Process
mobjProcess = System.Diagnost ics.Process.Sta rt(mobjStartInf o)
If (mobjProcess.St artInfo.Redirec tStandardError) Then
mobjErrorMonito r = New System.Threadin g.Thread(New
System.Threadin g.ThreadStart(A ddressOf MonitorStandard Output))
mobjErrorMonito r.Start()
End If
If (mobjProcess.St artInfo.Redirec tStandardOutput ) Then
mobjOutputMonit or = New System.Threadin g.Thread(New
System.Threadin g.ThreadStart(A ddressOf MonitorStandard Output))
mobjOutputMonit or.Start()
End If
Return mobjProcess
End Function
Public Sub [Stop]()
If Not (Me.mobjProcess .HasExited) Then
If (Me.mobjProcess .StartInfo.Redi rectStandardInp ut) Then
Me.mobjProcess. StandardInput.C lose()
End If
Me.mobjProcess. Kill()
Me.mobjProcess. WaitForExit()
Me.mobjProcess. Close()
End If
If Not (Me.mobjOutputM onitor Is Nothing) Then Me.mobjOutputMo nitor.Abort()
If Not (Me.mobjErrorMo nitor Is Nothing) Then Me.mobjErrorMon itor.Abort()
RaiseEvent Stopped()
End Sub
Public Event StandardOutputR eadLineHandler( ByVal lineText As String)
Public Event StandardErrorRe adLineHandler(B yVal lineText As String)
Public Event Stopped()
Public Event Exited()
Private Sub MonitorStandard Output()
Try
Dim line As String
line = Me.mobjProcess. StandardOutput. ReadLine()
While Not (line Is Nothing)
RaiseEvent StandardOutputR eadLineHandler( line)
line = Me.mobjProcess. StandardOutput. ReadLine()
End While
If (line Is Nothing) Then Me.Stop()
Catch ex As System.Exceptio n
Return
End Try
End Sub
Private Sub MonitorStandard Error()
Try
Dim line As String
line = Me.mobjProcess. StandardError.R eadLine()
While Not (line Is Nothing)
RaiseEvent StandardErrorRe adLineHandler(l ine)
line = Me.mobjProcess. StandardError.R eadLine()
End While
Catch ex As System.Exceptio n
Return
End Try
End Sub
Public Sub WriteStandardIn put(ByVal text As String)
Me.mobjProcess. StandardInput.W rite(text)
End Sub
Public Sub WriteStandardIn putLine(ByVal textLine As String)
Me.mobjProcess. StandardInput.W riteLine(textLi ne)
End Sub
Protected Overrides Sub Finalize()
mobjStartInfo = Nothing
mobjProcess = Nothing
mobjErrorMonito r = Nothing
mobjOutputMonit or = Nothing
MyBase.Finalize ()
End Sub
Private Sub mobjProcess_Exi ted(ByVal sender As Object, ByVal e As
System.EventArg s) Handles mobjProcess.Exi ted
RaiseEvent Exited()
End Sub
Nov 20 '05 #1
1 5961
* "solex" <so***@nowhere. com> scripsit:
Hopefully someone has run into this error. I have written a class(source
below) that launches a thread to monitor the StandardOutput of a
System.Diagnost ics.Process, in particular I am executing the find.exe
program.

The application works perfectly in the development environment. As soon as
I execute the compiled program and start the find process I get an
"Applicatio n Error". The error states that the instruction 0x7552bb73
referenced memory at "0x00000000 0" the memor could not be read.


Does it work when using this code?

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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2

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

Similar topics

0
1733
by: marccruz | last post by:
Given an instance of System.Diagnostics.Process, how can I get the parent process o Given an instance of System.Diagnostics.Process, how can I get the child processes For example, I start a process which executes a script that starts a java program System.Diagnostics.Process proc = System.Diagnostics.Process() proc.StartInfo.FileName...
1
3034
by: Heiko Besemann | last post by:
Dear group, I created an aspx page using System.Diagnostics.Process() to launch "tracert" from shell and redirect output to Response.Output which prints it as text/plain into my browsers window. Now that works fine so far. My problem is that while tracert process is running and ASP ..NET is putting data into the pages output stream, my...
2
15460
by: andreas | last post by:
hi, In windows xp in the start launch menu when i put notepad "c:\test.txt" i get notepad with test.txt in it. in vb.net when i state system.diagnostics.process.start("notepad.exe" i get notepad but
11
3726
by: Nurit N | last post by:
This is the third newsgroup that I'm posting my problem. I'm sorry for the multiple posts but the matter becoming urgent. I hope this is the right place for it... I have created a very simple batch file (echo hello world) and was trying to retrieve the standard output but every time I run the code it returns ExitCode as 1.
0
1784
by: Daniel | last post by:
System.Diagnostics.Process.Start fails on windows server 2003 the process returns process.ExitCode == 0 but executing any process with System.Diagnostics.Process.Start on windows xp works fine. anything to do different for windows server 2003? some special permission for the process that executes another executable with...
0
849
by: Daniel | last post by:
C# windows service freezes on System.Diagnostics.Process.Start(info) When I launch PSCP from a C# windows service and launch pscp 0.53 there are no issues. but when I use C# windows service to launch pscp 0.58 C# freezes in System.Diagnostics.Process.Start(info)? pscp 0.58 works fine at command line, but causes C# to freeze on...
0
4175
by: Colin Williams | last post by:
I am using the code below to map network drive and then fire up an app in a sub dir of that drive. However when using the file open dialog from that app, drive K: appears just as Network drive K: (this could confuse users) rather than showing the path it is mapped to like in explorer. Using a batch file to execute these commands works great....
0
3005
by: =?Utf-8?B?UHVjY2E=?= | last post by:
-- Hi I'm using vs2005, .net 2 for windows application. The application I started using System.Diagnostics.Process is having a "listFiles.StandardOutput" buffer size problem. I was wondering where and how can I adjust the buffer size problem. I don't want to be limited to a set buffer size, is that possible? thank you. public static...
2
6859
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the program. That works for 95 %, but the other 5 % it doesn't. It seems to me that the started process just hangs, and therefor my program hangs, too...
0
7615
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7819
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8055
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7581
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5446
isladogs
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...
0
5165
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...
0
3566
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1149
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
858
bsmnconsultancy
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...

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.