Can't read from services standard output
On a Windows XP/VB.NET 2005 environment, I try to create a Windows Service that will call an external program every 2 secs and grab its output. The problem is that using the str=process.standardoutput.readline command, str returns null.
What seems really peculiar to me is the fact that when I tried to convert the service to a console application, everything worked fine!
The code I'm using is the following:
Public Class Service1
Private snmpget As Process = New Process()
Private s As String = "START"
Private sOut As StreamReader
Private t As Timer
Protected Overrides Sub OnStart(ByVal args() As String)
.FileName = "C:\SNMP\bin\snmpget.exe"
.WindowStyle = ProcessWindowStyle.Hidden
.UseShellExecute = False
.CreateNoWindow = True
.RedirectStandardOutput = True
.Arguments = "-v " & snmpVersion & " -c " & snmpCommunity & " " & snmpAgent & " " & snmpOID
t = New Timer(2000)
AddHandler t.Elapsed, AddressOf timerFired
.AutoReset = True
.Enabled = True
Private Sub timerFired(ByVal sender As Object, ByVal e As ElapsedEventArgs)
sOut = snmpget.StandardOutput
If snmpget.HasExited Then
s = sOut.ReadToEnd
Protected Overrides Sub OnStop()
Any ideas what's going wrong?
Last edited by padavrexi; 08-01-2006 at 06:05 AM.
Are you running your service under the same user account under which you ran your console test app? Have you selected the option to allow the service to "interact with desktop?"
Please post questions to the forums, where others may benefit.
I do not offer free assistance by e-mail. Thank you!
Last Post: 05-27-2008, 11:17 AM
By sirantonycartwr in forum Java
Last Post: 05-22-2006, 08:29 AM
Last Post: 08-09-2005, 01:11 AM
By Rob Teixeira in forum .NET
Last Post: 12-10-2001, 10:42 AM
By Denis Garon in forum Web
Last Post: 03-28-2000, 08:26 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL