oneliner failed on Win2k with space in path name

X

Xu Yang

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
 
M

Mina Naguib

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

Xu said:
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-----
 
T

tnitzke

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"
 
B

Bob Walton

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.
 
T

Tad McClellan

Xu Yang said:
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
 
X

Xu Yang

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top