Console app run as a service

Just starting out? Need help? Post your questions and find answers here.
lesserpanda
User
User
Posts: 65
Joined: Tue Feb 11, 2020 7:50 am

Console app run as a service

Post by lesserpanda »

Hi, I'd like to compile my Console App into an exe and run as a service.

I coded a quick test and used nssm and installed the exe as a service and ran it. Now, it runs fine though I can't see output in either the designated output file from nssm or eventviewer itself. How do I get some output into a file perhaps? And is this the right way to run it as a service.

Code: Select all


If OpenConsole()
  EnableGraphicalConsole(#True)
  ConsoleColor(10, 0)
  Repeat
  PrintN("Execute...")
  Delay(1000)
  ForEver
  CloseConsole()
EndIf
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Console app run as a service

Post by infratec »

Open a file in append mode
Write to the file
Close the file

Where is your problem exactly?
lesserpanda
User
User
Posts: 65
Joined: Tue Feb 11, 2020 7:50 am

Re: Console app run as a service

Post by lesserpanda »

What's best practice to run the PB App as a service?

Like nssm would output to stdout and stderr. However, how do I manage that with PB App?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Console app run as a service

Post by mk-soft »

A service does not have a console or GUI and therefore no connection to the user's desktop.
There is also something more to consider. Control commands to the service. Loops with delays, etc.
Search for 'Services' in the forum.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Console app run as a service

Post by Marc56us »

If your program does not need user interaction (i.e. stop/start), then it is easier to run it through the scheduler than to make it a service.
The scheduler can launch it:
- At PC startup
- At the start of the session
- At a certain time
- At regular intervals (which avoids taking up memory all the time)
It can write to files and launch a GUI
lesserpanda
User
User
Posts: 65
Joined: Tue Feb 11, 2020 7:50 am

Re: Console app run as a service

Post by lesserpanda »

Thanks for all the comments.

I'd like to make it a service because there are certain other existing monitoring services I can rely on to check on the service status easily.

Hopefully I can get more feedback on how everyone is doing this.
Post Reply