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

use warnings; use strict; use XML::LibXML; my $mkvext = 'mkvextract'; my ($self) = {}; $self->{xml} = XML::LibXML->new(); my $item = "F:\\My Folder\\split-001.mkv"; my $cmd = "$mkvext chapters $item"; open my $H, "$cmd |"; binmode $H; my $xml = $self->{xml}->load_xml(IO => $H);
The above is an example where I am able to reproduce the issue. I realize many people here will not be able to recreate the scenario (as you'll need MKVExtract and a MKV file with chapters) so I'll summarize. The above code is extracting an XML from the MKV then immediately loading it up with load_xml. The issue is that load_xml in this type of situation does not like that there is a space in the directory path ("My Folder"). I'm not sure how to work around the issue apart from using folders that contain no spaces. Below is the error. Any help would be greatly appreciated!
L:>Test.pl Entity: line 1: parser error : Document is empty Error: Unrecognized command line option 'Folder\split-001.mkv'. ^

Replies are listed 'Best First'.
Re: Load XML issues
by Corion (Patriarch) on Sep 18, 2014 at 08:12 UTC

    Did you check that your command line works outside of Perl?

    You will likely need to add proper shell quotes for the shell you're using.

    my $cmd = qq{$mkvext chapters "$item"};
      That did it! Thanks! To think I simply missed a quote... Man, I must have been tired...
Re: spaces in shell commands ( Win32::ShellQuote )
by Anonymous Monk on Sep 18, 2014 at 07:49 UTC

    The issue is that load_xml in this type of situation does not like that there is a space in the directory path ("My Folder").

    :) Nope, load_xml doesn't care, open on the other hand might if the shell cares ... learn to work your shell :) Win32::ShellQuote

      I was going to say that you can avoid the shell enterely passing the command and arguments to open separately:
      open my $H, '-|', $mkvext, 'chapters', $item;
      Then, I remembered that on Windows, at the OS level, a command is not invoked as a list of program+arguments but as a single line so, I don't now what would happen.

      Does the execv emulation used by perl internally take care of quoting the arguments properly?

        salva, unfortunately you are right. This is what will happen:
        List form of pipe open not implemented at -e line 1.

        L*
        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
        Does the execv emulation used by perl internally take care of quoting the arguments properly?

        As far as I can tell Perl doesn't emulate execv and execvp on Windows, instead the emulation is provided by Windows. According to that doc, "Spaces embedded in strings may cause unexpected behavior", so it seems the answer to your question would be No. Hence the need for modules like Win32::ShellQuote.