473,385 Members | 1,782 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,385 software developers and data experts.

System.Diagnostics.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.Diagnostics.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
"Application Error". The error states that the instruction 0x7552bb73
referenced memory at "0x000000000" 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.Collections.Specialized
Imports System.Diagnostics
Imports System.IO
Imports System.Threading
Friend Class ProcessController
Private mobjStartInfo As ProcessStartInfo
Private WithEvents mobjProcess As System.Diagnostics.Process
Private mobjErrorMonitor As System.Threading.Thread
Private mobjOutputMonitor As System.Threading.Thread
Public Sub New(ByVal startInfo As ProcessStartInfo)
Me.mobjStartInfo = startInfo
End Sub
Public Sub New(ByVal filename As String, ByVal arguments As String, ByVal
environmentVariables As StringDictionary)
Dim fileInfo As System.IO.FileInfo
fileInfo = New System.IO.FileInfo(filename)
mobjStartInfo = New ProcessStartInfo
mobjStartInfo.FileName = fileInfo.FullName
mobjStartInfo.WorkingDirectory = fileInfo.DirectoryName
mobjStartInfo.Arguments = arguments
If Not (environmentVariables Is Nothing) Then
For Each var As String In environmentVariables.Keys
If (mobjStartInfo.EnvironmentVariables.ContainsKey(va r)) Then
mobjStartInfo.EnvironmentVariables(var) = environmentVariables(var)
Else
mobjStartInfo.EnvironmentVariables.Add(var, environmentVariables(var))
End If
Next
End If
mobjStartInfo.RedirectStandardOutput = True
mobjStartInfo.RedirectStandardError = True
mobjStartInfo.RedirectStandardInput = True
mobjStartInfo.UseShellExecute = False
End Sub
Public ReadOnly Property MyProcess() As Process
Get
Return (Me.mobjProcess)
End Get
End Property
Public Function Start() As Process
mobjProcess = System.Diagnostics.Process.Start(mobjStartInfo)
If (mobjProcess.StartInfo.RedirectStandardError) Then
mobjErrorMonitor = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf MonitorStandardOutput))
mobjErrorMonitor.Start()
End If
If (mobjProcess.StartInfo.RedirectStandardOutput) Then
mobjOutputMonitor = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf MonitorStandardOutput))
mobjOutputMonitor.Start()
End If
Return mobjProcess
End Function
Public Sub [Stop]()
If Not (Me.mobjProcess.HasExited) Then
If (Me.mobjProcess.StartInfo.RedirectStandardInput) Then
Me.mobjProcess.StandardInput.Close()
End If
Me.mobjProcess.Kill()
Me.mobjProcess.WaitForExit()
Me.mobjProcess.Close()
End If
If Not (Me.mobjOutputMonitor Is Nothing) Then Me.mobjOutputMonitor.Abort()
If Not (Me.mobjErrorMonitor Is Nothing) Then Me.mobjErrorMonitor.Abort()
RaiseEvent Stopped()
End Sub
Public Event StandardOutputReadLineHandler(ByVal lineText As String)
Public Event StandardErrorReadLineHandler(ByVal lineText As String)
Public Event Stopped()
Public Event Exited()
Private Sub MonitorStandardOutput()
Try
Dim line As String
line = Me.mobjProcess.StandardOutput.ReadLine()
While Not (line Is Nothing)
RaiseEvent StandardOutputReadLineHandler(line)
line = Me.mobjProcess.StandardOutput.ReadLine()
End While
If (line Is Nothing) Then Me.Stop()
Catch ex As System.Exception
Return
End Try
End Sub
Private Sub MonitorStandardError()
Try
Dim line As String
line = Me.mobjProcess.StandardError.ReadLine()
While Not (line Is Nothing)
RaiseEvent StandardErrorReadLineHandler(line)
line = Me.mobjProcess.StandardError.ReadLine()
End While
Catch ex As System.Exception
Return
End Try
End Sub
Public Sub WriteStandardInput(ByVal text As String)
Me.mobjProcess.StandardInput.Write(text)
End Sub
Public Sub WriteStandardInputLine(ByVal textLine As String)
Me.mobjProcess.StandardInput.WriteLine(textLine)
End Sub
Protected Overrides Sub Finalize()
mobjStartInfo = Nothing
mobjProcess = Nothing
mobjErrorMonitor = Nothing
mobjOutputMonitor = Nothing
MyBase.Finalize()
End Sub
Private Sub mobjProcess_Exited(ByVal sender As Object, ByVal e As
System.EventArgs) Handles mobjProcess.Exited
RaiseEvent Exited()
End Sub
Nov 20 '05 #1
1 5922
* "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.Diagnostics.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
"Application Error". The error states that the instruction 0x7552bb73
referenced memory at "0x000000000" 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
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...
1
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....
2
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...
11
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...
0
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....
0
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...
0
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:...
0
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...

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.