cygpath -s behaviour

Igor Pechtchanski pechtcha@cs.nyu.edu
Fri Sep 6 07:01:00 GMT 2002


On Fri, 6 Sep 2002, Watts, Simon (UK) wrote:

> Just spend a merry lunchtime tracking this behaviour down (it would be
> cruel to call it a bug):
>
> Recap:
>         cygpath -[mw]s "DIR"
> echos the file/directory DIR in shortened windows format (ie, mangles to
> 8.3 format).
>
> If a component part of "DIR" is not in 8.3 format, and does not exist in the
> directory structure, then (I presume) 'cygpath' cannot obtain the mangled
> form.  The upshot is that cygpath returns nothing.  It may set an error
> state, I havent checked.
>
> It would be useful if this was mentioned in the man page or '--help'.
>
> Is there any more useful behaviour?  All I am really trying to do in using
> the '-s' option is to mangle any componts of the path containing spaces
> (writing cross-platform scripts here...).
>
> What about an option to mangle only those elements of a path which (a) exist
> and (b) contain spaces?

Which version of cygwin do you have installed?  The latest cygpath should,
theoretically, print a message to stderr AND return an error code if
unable to get the short path (winsup/utils/cygpath.cc:161):

  DWORD len = GetShortPathName (filename, buf, MAX_PATH);
  if (len == 0 && GetLastError () == ERROR_INVALID_PARAMETER)
    {
      fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
               filename);
      exit (2);
    }

With similar tests every time GetShortPathName is called.  Are you losing
your stderr, by any chance, e.g. 'cygpath -ws $PATH 2>/dev/null'?

As for mangling only the parts of the path that contain spaces, try
something like

perl -e 'local $_=$ARGV[0];while(/ /){s,^(.*/)([^/]* [^/\n]*),$a=`cd "$1" && /bin/cygpath -ws "$2"`;chomp($a);$1.$a,e};print "$_\n"'

or, to pipe the path in,

perl -pe 'while(/ /){s,^(.*/)([^/]* [^/\n]*),$a=`cd "$1" && /bin/cygpath -ws "$2"`;chomp($a);$1.$a,e}'

You can also check the return code of cygpath in the script if you wish,
to filter out the paths that don't have a short name.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95.  Something is wrong here. -- SC sig file


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list