Can't read from services standard output


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Can't read from services standard output

  1. #1
    Join Date
    Aug 2006
    Posts
    1

    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
    .Start()
    End With
    End Sub

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

    Protected Overrides Sub OnStop()
    t.Stop()
    t.Dispose()
    End Sub

    End Class


    Any ideas what's going wrong?

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

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    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
    http://www.philweber.com

    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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