[sf-perl] Windows Perl question

Steve Fink sphink at gmail.com
Mon Jan 22 11:22:58 PST 2007


qw is for taking a set of tokens, separated by whitespace, and returning a
list. You're assigning into a scalar, which makes no sense. In this case, it
will give you the last value in the list, which is
"Files\Rational\ClearCase...". I think you meant q instead of qw.

  my $commLine = q!"\\Program
Files\\Rational\\ClearCase\\bin\\clearexplorer.exe"!;

might do what you want. Although you might want to check if Windows will let
you use forward slashes instead of backslashes; if so, you can use:

  my $commLine = q!"/Program
Files/Rational/ClearCase/bin/clearexplorer.exe"!;

Another option to avoid the problem of quoting is to prevent system from
passing the command to the shell. If you had any command-line arguments,
that would be easy, but since you don't, you can force it with the bizarre

  my $commLine = q!\\Program
Files\\Rational\\ClearCase\\bin\\clearexplorer.exe!;
  system {$commLine} $commLine;

This uses the first $commLine as the program to run, and the second to tell
the OS what the name of the program that you're running is (in case you want
to lie.) So this should also work:

  my $commLine = q!\\Program
Files\\Rational\\ClearCase\\bin\\clearexplorer.exe!;
  system {$commLine} "clear explorer, dude";

Strangely, further arguments come after the second one. So if you were to
pass in the value 12, this would become:

  my $commLine = q!\\Program
Files\\Rational\\ClearCase\\bin\\clearexplorer.exe!;
  system {$commLine} "blahblah", "12";

or

  my $commLine = q!\\Program
Files\\Rational\\ClearCase\\bin\\clearexplorer.exe!;
  system {$commLine} ("blahblah", "12");

Except in that case, you have a command line argument, so it's much easier:

  my @command = (q!\\Program
Files\\Rational\\ClearCase\\bin\\clearexplorer.exe!, "12");
  system @command;

On 1/22/07, nheller at silcon.com <nheller at silcon.com> wrote:
>
>
> Here's a short example script.  My system can't find the executable.  I'm
> sure there must be an easy solution - but what?
>
> #!Perl  -w
>
> use warnings;
> use strict;
>
> my $commLine = qw "\"\\Program
> Files\\Rational\\ClearCase\\bin\\clearexplorer.exe\"";
>
> system $commLine;
>
> my $foo = 1;
>
> Neil Heller
>
>
> > On Sat, Jan 20, 2007 at 02:12:12PM -0800, Michael Friedman wrote:
> >
> >> Sometimes it pays to ask the seemingly obvious question...
> >> Did you try putting the path in quotes?
> >
> > Exactly my thought.
> >
> >> How about escaping the space?  "Program\ Files".
> >
> > In Windows, I believe, you'd have to do something like this:
> >
> >     system qq{chdir "Program Files"};
> >     # or
> >     system qq{chdir "$dir"};
> >
> > --the reason being that the Windows command shell doesn't have single
> > quotes the way bash (for instance) does.
> >
> > Caveat hacker:  I don't have a Windows box, so I didn't test this.  I'm
> > just going from memory.
> >
> > --
> > Quinn Weaver, independent contractor  |  President, San Francisco Perl
> > Mongers
> > http://fairpath.com/quinn/resume/     |  http://sf.pm.org/
> > _______________________________________________
> > SanFrancisco-pm mailing list
> > SanFrancisco-pm at pm.org
> > http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
> >
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20070122/bc518b34/attachment.html 


More information about the SanFrancisco-pm mailing list