soliplaya has asked for the wisdom of the Perl Monks concerning the following question:

Hi. On a Windows XP machine, I am experiencing an error, typically "read error at C:/Perl/site/lib/XML/Parser/Expat.pm line 469", or "read error at C:/Perl/site/lib/XML/SAX/ExpatXS.pm line 163". The funny part is : - 1) I use the same code in a series of programs, and only one program gives this error, although they all do essentially the same at that point, the same way (read and parse the same XML configuration file) - 2) the error-prone program gets this error *only* when it is started as a Windows Service. It can also be started in a Windows console window, and in that case it does not get the error. - 3) On other Windows XP machines, the same error does not occur. Changing the XML parser used (through XML::Simple::PREFERRED_PARSER) changes the location of the error (see above), but there is always an error. I am puzzled. Anyone seen this before ?
  • Comment on read error in XML parsers, Windows XP Service only

Replies are listed 'Best First'.
Re: read error in XML parsers, Windows XP Service only
by BrowserUk (Patriarch) on Apr 20, 2008 at 17:53 UTC

    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.
      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.
Re: read error in XML parsers, Windows XP Service only
by Jenda (Abbot) on Apr 20, 2008 at 23:02 UTC

    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?

      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.
Re: read error in XML parsers, Windows XP Service only
by sub_chick (Hermit) on Apr 20, 2008 at 17:54 UTC
    Is it possible to show the code you are using? This sounds like it is either install error being as your program errors out on one specific Windows XP machine and not the others or it can be that the program that is giving you an error is flawed when you insert this code (maybe it is failing to call the module. But then again, one cannot be sure until what you're working with can be seen.


    Es gibt mehr im Leben als Bücher, weißt du. Aber nicht viel mehr. - (Die Smiths)"
      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?