Hello,

I'm trying to call a Perl script from another passing few arguments. One of my arguments has a path variable which has white spaces embedded in it. I know how to escape the white space when I know the value of the variable in advance. But how do I escape the white spaces in a scalar variable that's being passed as an argument to a script called inside another script.

For instance, we could escape the white space and read $path as one whole string till the end

 my $path = "C:/\"Program Files\"/\"Perl Express\"/example.txt;

Now, I'm trying to pass one such $path variable and a hash as arguments to a script.

@ARGV = ("C:/Program Files/Perl Express/sample.txt", "some hash"); # I + dunno the path value in advance. This is just an example system("C:/Perl/bin/perl.exe /path/to/the/script @ARGV");

When I try to print this ARGV in the other script, it reads C:/Program and Files/Perl as first and second arguments.

Is there a way that I could escape such white spaces?

Thanks,

In reply to How to escape white space in command line arguments by GoForIt

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.