Thread Projekt - Perl in Windows 2008 (47 answers)
Opened by WilliamW at 2013-10-17 18:11

WilliamW
 2013-10-23 13:46
#171431 #171431
User since
2013-10-17
27 Artikel
BenutzerIn
[default_avatar]
2013-10-23T11:30:46 GwenDragon
Du musst dem System auch erst mal den Dienst erstellen.
Stichwort Win32::Daemon::CreateService
http://search.cpan.org/~jdb/Win32-Daemon-20110117/...


Genau. Den Service habe ich wie folgt erstellt.
Also im Prinzip genau nach Vorlage, wobei die Perl(pl)-Datei, welche als Service gestartet werden soll, der Einfachheit im "C:\"-Verzeichnis liegt und "testService.pl" heißt.

"testStart.pl"
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/perl -w
use Win32::Daemon;
# If using a compiled perl script (eg. myPerlService.exe) then
# $ServicePath must be the path to the .exe as in:
# $ServicePath = 'c:\CompiledPerlScripts\myPerlService.exe';
# Otherwise it must point to the Perl interpreter (perl.exe) which
# is conviently provided by the $^X variable...
my $ServicePath = $^X;

# If using a compiled perl script then $ServiceParams
# must be the parameters to pass into your Perl service as in:
# $ServiceParams = '-param1 -param2 "c:\\Param2Path"';
# OTHERWISE
# it MUST point to the perl script file that is the service such as:
my $ServiceParams = 'c:\testService.pl -param1 -param2 "c:\\Param2Path"';


%Hash = (
machine => '',
name => 'PerlTest',
display => 'Oh my GOD, Perl is a service!',
path => $ServicePath,
user => '',
pwd => '',
description => 'Some text description of this service',
parameters => $ServiceParams
);
if( Win32::Daemon::CreateService( \%Hash ) )
{
print "Successfully added.\n";
}
else
{
print "Failed to add service: " . Win32::FormatMessage( Win32::Daemon::GetLastError() ) . "\n";
}


Desweiteren habe ich noch ein Programm geschrieben welches den besagten Service löscht. Und das funktioniert sogar, wobei ich als Ausgabe "success 1" bekomme. Bedeutet der Service wurde wirklich erstellt.

"testDelete.pl"
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/perl -w
use Win32::Daemon;

$Maschine = "";
$ServiceName = "PerlTest";
$boolean = Win32::Daemon::DeleteService($Maschine,$ServiceName);

if ( 0 != $boolean )
{
print "success" . " " . $boolean;
} else
{
print "fail";
}


Wenn ich aber nach dem ausführen der "testStart.pl" die "testService.pl" selber ausführe, dann bleibt dieser wie zuvor in der (endlos) Schleife hängen. Was muss ich also genau machen, nachdem ich den Service mit der "testStart.pl" erstellt habe ? Oder habe ich evtl. im Quellcode was falsch geschrieben ?
Last edited: 2013-10-23 14:15:45 +0200 (CEST)

View full thread Projekt - Perl in Windows 2008