oneliner failed on Win2k with space in path name

Discussion in 'Perl Misc' started by Xu Yang, Jul 7, 2003.

  1. Xu Yang

    Xu Yang Guest

    Hi,

    I have an oneliner Perl script (see below) works fine when the path
    name is 8.3 format on Win2K, but failed after it operated on a path
    name contains space:

    c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt

    If I change the "c:\usr" to "c:\program files", it failed with error:
    Can't open c:\program files\*.tt.
    I double quote the path, did not help either.

    Is this because the old version (5.x) of perl I am using?


    Xu
    Xu Yang, Jul 7, 2003
    #1
    1. Advertising

  2. Xu Yang

    Mina Naguib Guest

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Xu Yang wrote:
    > Hi,
    >
    > I have an oneliner Perl script (see below) works fine when the path
    > name is 8.3 format on Win2K, but failed after it operated on a path
    > name contains space:
    >
    > c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt


    A shorter version of this is:

    perl -ne 'print "$ARGV.#$_" if /^define/'

    > If I change the "c:\usr" to "c:\program files", it failed with error:
    > Can't open c:\program files\*.tt.
    > I double quote the path, did not help either.


    I'm not 100% sure how filename globbing works under windows' shell, but try the old 8.3
    compatability naming, it might work:

    c:\progra~1\*.tt


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.1 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQE/CdB4eS99pGMif6wRAiJ4AJ9A2RRreI7fIl5HjNscETWpUsUOyQCdEdBT
    dlH3Nu72i4G3/IYh9YCJ+fc=
    =k2QF
    -----END PGP SIGNATURE-----
    Mina Naguib, Jul 7, 2003
    #2
    1. Advertising

  3. Xu Yang

    tnitzke Guest

    Xu Yang wrote:
    :
    : c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt
    :
    : If I change the "c:\usr" to "c:\program files", it failed with error:
    : Can't open c:\program files\*.tt.
    : I double quote the path, did not help either.
    :

    You'll want to quote your arguments when they contain spaces. Try the following.

    perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" "c:\program files\*.tt"

    --------------
    tnitzke
    ($_=qq-dfwbh%nxigh%obchvsf%dsfz%voqysfn-)=~tr+%o-za-mn+ a-y'+;eval
    tnitzke, Jul 7, 2003
    #3
  4. Xu Yang

    Bob Walton Guest

    Xu Yang wrote:

    ....


    > I have an oneliner Perl script (see below) works fine when the path
    > name is 8.3 format on Win2K, but failed after it operated on a path
    > name contains space:
    >
    > c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt


    '--------------------------------------------------^
    *please* copy/paste working code, don't just type it in -- the above as
    given doesn't compile because the # is seen as the start of a Perl
    comment, resulting in unbalanced braces. I assume it should be ...'#'...


    >
    > If I change the "c:\usr" to "c:\program files", it failed with error:
    > Can't open c:\program files\*.tt.
    > I double quote the path, did not help either.
    >
    > Is this because the old version (5.x) of perl I am using?
    >
    >
    > Xu
    >


    Your error message indicates that the command "shell" got the correct
    filename, but that such a file was not actually present. Check in your
    "c:\program files" directory and see if there are any *.tt files in that
    directory. Usually, there aren't any files in that directory -- only
    additional subdirectories. The problem should have nothing to do with
    your version of Perl, and, in fact, doesn't appear to be a Perl problem
    at all.

    --
    Bob Walton
    Bob Walton, Jul 8, 2003
    #4
  5. Xu Yang <> wrote:

    > I have an oneliner Perl script (see below) works fine

    ^^^^^^^^^^
    ^^^^^^^^^^
    > c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt

    ^^^

    I'm having trouble believing you there...

    [ Have you seen the Posting Guidelines that are posted here frequently? ]


    > Is this because the old version (5.x) of perl I am using?



    No, it is because of the silly shell that you are forced to use.

    You must expand the glob() in your Perl code, if your shell won't
    expand it for you. Something like:

    c:\perl -ne "BEGIN{ @ARGV=<$ARGV[0]> } print qq($ARGV#$_) if /^define/" *.tt


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jul 8, 2003
    #5
  6. Xu Yang

    Xu Yang Guest

    All,
    Thanks for the help from everyone!
    I would apologize for my careless when I post my code, the left single
    quote around the # was missed when I cut and paste.
    the shortname does work as everyone expected. But I have to do more
    work from the code who calls this oneliner in order to get the short
    name. I was thinking use the Win32's GetShortName(), unfortunately,
    the old version Perl I have does not have this call. So I end up with
    converting the long name to short name.

    Thanks again.
    Xu

    Mina Naguib <> wrote in message news:<XfkOa.36870$>...
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Xu Yang wrote:
    > > Hi,
    > >
    > > I have an oneliner Perl script (see below) works fine when the path
    > > name is 8.3 format on Win2K, but failed after it operated on a path
    > > name contains space:
    > >
    > > c:\perl -e "while(<>) {if(/^define/){print $ARGV.#'.$_;}}" c:\usr\*.tt

    >
    > A shorter version of this is:
    >
    > perl -ne 'print "$ARGV.#$_" if /^define/'
    >
    > > If I change the "c:\usr" to "c:\program files", it failed with error:
    > > Can't open c:\program files\*.tt.
    > > I double quote the path, did not help either.

    >
    > I'm not 100% sure how filename globbing works under windows' shell, but try the old 8.3
    > compatability naming, it might work:
    >
    > c:\progra~1\*.tt
    >
    >
    > -----BEGIN PGP SIGNATURE-----
    > Version: GnuPG v1.2.1 (GNU/Linux)
    > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
    >
    > iD8DBQE/CdB4eS99pGMif6wRAiJ4AJ9A2RRreI7fIl5HjNscETWpUsUOyQCdEdBT
    > dlH3Nu72i4G3/IYh9YCJ+fc=
    > =k2QF
    > -----END PGP SIGNATURE-----
    Xu Yang, Jul 8, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shuo Xiang

    Stack space, global space, heap space

    Shuo Xiang, Jul 9, 2003, in forum: C Programming
    Replies:
    10
    Views:
    2,869
    Bryan Bullard
    Jul 11, 2003
  2. Christian Seberino
    Replies:
    21
    Views:
    1,629
    Stephen Horne
    Oct 27, 2003
  3. Ian Bicking
    Replies:
    2
    Views:
    984
    Steve Lamb
    Oct 23, 2003
  4. Ian Bicking
    Replies:
    2
    Views:
    708
    Michael Hudson
    Oct 24, 2003
  5. Alex Martelli

    "number-in-base" ``oneliner''

    Alex Martelli, Oct 29, 2004, in forum: Python
    Replies:
    21
    Views:
    647
    Andrea Griffini
    Nov 1, 2004
Loading...

Share This Page