DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2006

    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:

    Imports System.Diagnostics
    Imports System.Timers
    Imports System.IO

    Public Class Service1

    'Process controls
    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)
    With snmpget.StartInfo
    .FileName = "C:\SNMP\bin\snmpget.exe"
    .WindowStyle = ProcessWindowStyle.Hidden
    .UseShellExecute = False
    .CreateNoWindow = True
    .RedirectStandardOutput = True
    .Arguments = "-v " & snmpVersion & " -c " & snmpCommunity & " " & snmpAgent & " " & snmpOID
    End With

    t = New Timer(2000)
    AddHandler t.Elapsed, AddressOf timerFired
    With t
    .AutoReset = True
    .Enabled = True
    End With
    End Sub

    Private Sub timerFired(ByVal sender As Object, ByVal e As ElapsedEventArgs)
    sOut = snmpget.StandardOutput
    If snmpget.HasExited Then
    s = sOut.ReadToEnd
    End If
    End Sub

    Protected Overrides Sub OnStop()
    End Sub

    End Class

    Any ideas what's going wrong?

    Last edited by padavrexi; 08-01-2006 at 06:05 AM.

  2. #2
    Join Date
    Nov 2003
    Portland, OR
    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?"
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Replies: 5
    Last Post: 05-27-2008, 11:17 AM
  2. Cannot append file (or read now), why wont it work?
    By sirantonycartwr in forum Java
    Replies: 6
    Last Post: 05-22-2006, 08:29 AM
  3. Replies: 26
    Last Post: 08-09-2005, 01:11 AM
  4. .Net: Microsoft's window on Web services
    By Rob Teixeira in forum .NET
    Replies: 37
    Last Post: 12-10-2001, 10:42 AM
  5. Replies: 0
    Last Post: 03-28-2000, 08:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center