By default, services run under the 'local system' account and have restricted priviledges. You should configure the service to run under an account with access to the files in question.
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
The service is running under a user-id, not LocalSystem. When I use the same user-id to login into Windows XP, and run the same program in a Command Window, it works flawlessly.
I also have 3 other programs, which do the same thing using essentially the same code, and which run fine both in a Command window and as a service. They all call the XML parser to parse the same file (a common XML parameter file).
I also use the same 4 programs on a number of other Windows XP machines, where they all run fine in console mode and as services.
That's why I'm puzzled.
| [reply] |
Try to read the XML by simple open my $in, '<', $path. Can you open it? Any chance you use relative paths and the working directory is different? Any chance the file is on a mapped network drive?
| [reply] [d/l] |
Ok, thanks guys. Your various messages made me go back and look really hard at what I was doing before parsing the file, and I found that indeed, when started as a service, the path to the file-to-parse was incorrect.
Basically, when starting as a service, the startup directory is not the same as when starting in a console. My program "knows that", and does a chdir() in that case. But I ended up pre-pending the current directory path twice to my filename, and trying to parse "C:/XYZC:/XYZ/filename.ini" when running as a service.
Entirely my fault, but your comments were very useful in helping convince me that I was not the victim of some obscure Perl/XML-Parser/WinXP scheme.
Many thanks.
| [reply] |
| [reply] |
This is a very large program (5000 lines), but here are some snippets :
#!/usr/bin/perl
# CVS version : $Id: MiraLoader.pl,v 2.13 2008-02-03 15:11:46 efs Exp
+$
use strict "vars";
use warnings;
use FindBin qw($Bin);
use lib "$Bin/../lib";
use File::Basename;
use File::Copy;
use Getopt::Std;
use Encode;
use XML::Simple;
#$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
#[...]
log_msg(0,"Going to parse INI file.");
$INITBL = parse_INI("$MYTOPDIR/$MYINI",$SVCNAME); # $INITBL = ref
+ to Parameter table
# parse_INI dies in case of errors, so if we're here, it's ok
log_msg(0,"INI file parsed.");
#[...]
sub parse_INI {
#############
my $IniFile = shift; # INI file name
my $MYTAG = shift; # tag of "my" section
my $IniRef; # the returned ref.
my ($MIRA,$MYSECT);
my $SectRef;
my ($Val,@SplitVals);
my $Msg = "Required directory not found or insufficient permissions :
+";
my $MsgSect = "Required section missing in INI file :";
my $MsgFil = "Required directory/file not found or insufficient permis
+sions";
my $MsgParam = "Required parameter missing in INI file :";
my $MsgParam2 = "Parameter in INI file has invalid value :";
my $fh;
log_msg(0,"==>parse_INI()") if $Debug>1;
unless (open($fh,'<',$IniFile)) {
die_msg(0,"** Cannot open INI file \"$IniFile\" **") if $Debug
+;
}
# Create an XML::Simple object with default parameters,
my $XMLOBJ = new XML::Simple(
keeproot => 1,
forcearray => 0,
# keyattr => 'Id',
forcecontent => 1,
contentkey => 'Value',
);
$IniRef = $XMLOBJ->XMLin($fh); # ***
close $fh;
#[...]
}
As far as I can tell, it crashes with the error on the line marked "***" above.
But I have 3 other programs, which do just about the same as above, and which do not experience this problem.
With the line
$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
commented out as above, the message is :
read error at C:/Perl/lib/XML/Parser/Expat.pm line 469
With the same line set to :
$XML::Simple::PREFERRED_PARSER = 'XML::SAX::ExpatXS';
then the error message is :
read error at C:/Perl/site/lib/XML/SAX/ExpatXS.pm line 163
I thus assume it must be some cause common to both parsers, and external to the parser itself. But why then do other programs running on the same XP machine and using exactly the same logic and parser, parsing the same XML file, not crash, and why does this one crash only when run as a service, and not in a console (running under the same non LocalSystem user-id in both console and service mode?
| [reply] [d/l] |
eval{ $IniRef = $XMLOBJ->XMLin($fh) }
or die "XMLin failed with $!, [$^E]";
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] [d/l] |