• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 21:37
CEST 03:37
KST 10:37
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9uThermal's 2v2 Tour: $15,000 Main Event18
Community News
Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris31Weekly Cups (Aug 11-17): MaxPax triples again!13Weekly Cups (Aug 4-10): MaxPax wins a triple6SC2's Safe House 2 - October 18 & 195
StarCraft 2
General
#2: Serral - Greatest Players of All Time #1: Maru - Greatest Players of All Time I hope balance council is prepping final balance Geoff 'iNcontroL' Robinson has passed away Aligulac - Europe takes the podium
Tourneys
Esports World Cup 2025 Sparkling Tuna Cup - Weekly Open Tournament Maestros of The Game—$20k event w/ live finals in Paris WardiTV Mondays RSL: Revival, a new crowdfunded tournament series
Strategy
Custom Maps
External Content
Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies Mutation # 485 Death from Below
Brood War
General
BSL Polish World Championship 2025 20-21 September BGH Auto Balance -> http://bghmmr.eu/ ASL Season 20 Ro24 Groups Flash On His 2010 "God" Form, Mind Games, vs JD No Rain in ASL20?
Tourneys
[Megathread] Daily Proleagues [IPSL] CSLAN Review and CSLPRO Reimagined! [ASL20] Ro24 Group F [ASL20] Ro24 Group D
Strategy
Simple Questions, Simple Answers Fighting Spirit mining rates [G] Mineral Boosting Muta micro map competition
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread General RTS Discussion Thread Dawn of War IV Path of Exile
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine The year 2050 European Politico-economics QA Mega-thread
Fan Clubs
INnoVation Fan Club SKT1 Classic Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
High temperatures on bridge(s) Gtx660 graphics card replacement Installation of Windows 10 suck at "just a moment"
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
Breaking the Meta: Non-Stand…
TrAiDoS
INDEPENDIENTE LA CTM
XenOsky
[Girl blog} My fema…
artosisisthebest
Sharpening the Filtration…
frozenclaw
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1194 users

C# programming help?

Blogs > Phyre
Post a Reply
Phyre
Profile Blog Joined December 2006
United States1288 Posts
Last Edited: 2009-10-28 22:02:39
October 28 2009 22:01 GMT
#1
Just to get it out of the way, this isn't a homework thread. I've been out of school for quite some time now. If this somehow breaks a TL rule though, I'm sorry and I'll happily accept this being removed. That said...

I'm having a great deal of difficult figuring out how to redirect standard output of a running windows service to a simple console app. This is being done in C#. The service is really simple, it just console.writelines some text every few seconds. I want my console app to simply echo the service's output.

I got standard output redirection working just fine when redirecting output from one console app to another console app. Doing that for a service is proving difficult.

I used this to redirect from one console app to another: http://www.c-sharpcorner.com/UploadFile/edwinlima/SystemDiagnosticProcess12052005035444AM/SystemDiagnosticProcess.aspx

Doesn't seem like I can apply that to a service though as far as I can tell.

"Oh no, I got you with your pants... on your face... That's not how you wear pants." - Nintu, catching 1 hatch lurks.
prOxi.swAMi
Profile Blog Joined November 2004
Australia3091 Posts
October 28 2009 23:08 GMT
#2
Just out of curiosity, why would you want a service to have any visual aspects anyway? If you need visual aspects, a service is probably not the right solution to the problem...
Oh no
b3h47pte
Profile Blog Joined May 2007
United States1317 Posts
Last Edited: 2009-10-28 23:23:49
October 28 2009 23:22 GMT
#3
i wrote a service before which communicated with an app on the desktop. One viable option on C++ i believe was to use SendMessage() - part of the Win32 API - to send messages from the service to the application. However the option I ended up using as SendMessage wasn't exactly passing parameters correctly, was i had the computer essentially send UDP packets to itself... definitely not your most ideal solution but it works. Since you're using C# i'm going to assume that the .NET framework has some networking solution so you can use that.

So in your service you would have a loop or function or however you implement it that sends a data packet to your computer's ip address (127.0.0.1) and a specific port and just have the console app listen on that port for any packets and open the packet, get the string, and print the string.

That's atleast the way I would probably do it.
As i said before, this is most likely NOT the best way to do it as i'm sure .NET has other ways of accomplishing this but rather this is the way I've done in the past (granted using C++..) and I know works.

I hope i answered your question and good luck! :3
prOxi.swAMi
Profile Blog Joined November 2004
Australia3091 Posts
October 29 2009 01:22 GMT
#4
Surely you don't need to use networking... I'm sure you can do what you're trying to do using Win32 interop
Oh no
b3h47pte
Profile Blog Joined May 2007
United States1317 Posts
October 29 2009 02:39 GMT
#5
Yes i know but i'm just saying it is an option although probably not the most viable one.
Phyre
Profile Blog Joined December 2006
United States1288 Posts
October 29 2009 03:19 GMT
#6
On October 29 2009 08:08 prOxi.swAMi wrote:
Just out of curiosity, why would you want a service to have any visual aspects anyway? If you need visual aspects, a service is probably not the right solution to the problem...

Well, we had a server program that could either run as a console app or as a service. Running as a console app we could see what the server is doing via console output but had the disadvantage of shutting down if someone accidentally logged off, remote desktop'ed in, etc. If we run it as a service we get around those accidental interruption problems but then we can't check to see what's going on.

So the solution I was tasked with making is a C# front end that can start the original program as a service and then read the console output from it. Thus the C# front end could go down due to someone logging off but that wouldn't affect the service and if we ever need to check up on the server we just bring the front end back online so we can see the console output.

I'm not sure if that is the optimal solution but that is what I was told to make.
"Oh no, I got you with your pants... on your face... That's not how you wear pants." - Nintu, catching 1 hatch lurks.
MasterOfChaos
Profile Blog Joined April 2007
Germany2896 Posts
October 29 2009 09:07 GMT
#7
Why don't you simple write the service so it logs it's output to a file? You might even be able to do that by piping stdout to the file.
LiquipediaOne eye to kill. Two eyes to live.
Phyre
Profile Blog Joined December 2006
United States1288 Posts
Last Edited: 2009-10-29 15:44:58
October 29 2009 15:00 GMT
#8
On October 29 2009 18:07 MasterOfChaos wrote:
Why don't you simple write the service so it logs it's output to a file? You might even be able to do that by piping stdout to the file.

The service already does log it's output to a file. Another reason for the new front end is to make the console output more readable via color coding and filtering options. Pretty sure color coding can be done on a console app as well, but as far as I know filtering the output isn't so easily done in a console app.
"Oh no, I got you with your pants... on your face... That's not how you wear pants." - Nintu, catching 1 hatch lurks.
Phyre
Profile Blog Joined December 2006
United States1288 Posts
Last Edited: 2009-10-29 17:59:12
October 29 2009 15:59 GMT
#9
Little change in plans. The service is apparently not using console.writeline(), rather it is writing to an eventlog. I'm not familiar with the use of event logs, time to start reading up on that. Not sure if this makes things easier or harder.

If anyone has any ideas on how to grab the event log output from a C++ service and output that to a C# frontend it would be much appreciated.

Edit: Yeah, this event log stuff seems like it will make life a lot easier. Sorry for the mixup guys, thanks for the help.
"Oh no, I got you with your pants... on your face... That's not how you wear pants." - Nintu, catching 1 hatch lurks.
garista
Profile Joined January 2003
Germany165 Posts
October 29 2009 20:46 GMT
#10
Use Microsoft's Log Parser, it can read text files but also the "Windows Event Viewer such as System, Application, and Security", it can even be used remotely.
Disclaimer: I haven't used it, but that's what their website states.
Please log in or register to reply.
Live Events Refresh
Replay Cast
00:00
SEL S2 Championship: Ro16
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft188
SpeCial 137
ProTech79
RuFF_SC2 41
Nina 39
StarCraft: Brood War
Artosis 735
Sharp 48
Icarus 3
Beast 2
Dota 2
monkeys_forever946
League of Legends
JimRising 302
Counter-Strike
Stewie2K771
taco 190
Super Smash Bros
hungrybox506
Mew2King20
Other Games
tarik_tv13368
summit1g8554
Day[9].tv841
shahzam631
C9.Mang0319
ViBE213
Maynarde123
ROOTCatZ0
Organizations
StarCraft 2
CranKy Ducklings133
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• OhrlRock 1
• intothetv
• AfreecaTV YouTube
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• Azhi_Dahaki2
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Doublelift4336
• Stunt267
Other Games
• Day9tv841
Upcoming Events
The PondCast
8h 23m
WardiTV Summer Champion…
9h 23m
herO vs MaxPax
Clem vs Classic
Replay Cast
22h 23m
LiuLi Cup
1d 9h
MaxPax vs TriGGeR
ByuN vs herO
Cure vs Rogue
Classic vs HeRoMaRinE
Cosmonarchy
1d 14h
OyAji vs Sziky
Sziky vs WolFix
WolFix vs OyAji
Big Brain Bouts
1d 14h
Iba vs GgMaChine
TriGGeR vs Bunny
Reynor vs Classic
Serral vs Clem
BSL Team Wars
1d 17h
Team Hawk vs Team Dewalt
BSL Team Wars
1d 17h
Team Hawk vs Team Bonyth
SC Evo League
2 days
TaeJa vs Cure
Rogue vs threepoint
ByuN vs Creator
MaNa vs Classic
Maestros of the Game
2 days
ShoWTimE vs Cham
GuMiho vs Ryung
Zoun vs Spirit
Rogue vs MaNa
[ Show More ]
[BSL 2025] Weekly
2 days
SC Evo League
3 days
Maestros of the Game
3 days
SHIN vs Creator
Astrea vs Lambo
Bunny vs SKillous
HeRoMaRinE vs TriGGeR
BSL Team Wars
3 days
Team Bonyth vs Team Sziky
BSL Team Wars
3 days
Team Dewalt vs Team Sziky
Monday Night Weeklies
4 days
Replay Cast
4 days
Sparkling Tuna Cup
5 days
Replay Cast
6 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 1
uThermal 2v2 Main Event
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
Acropolis #4 - TS1
CSL Season 18: Qualifier 2
SEL Season 2 Championship
WardiTV Summer 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

CSL 2025 AUTUMN (S18)
LASL Season 20
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
Maestros of the Game
EC S1
Sisters' Call Cup
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
Roobet Cup 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.