This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: example needed pls: `cygpath -c <HANDLE>'

Soren A wrote:

> OK, "what's UP with this bizarre thing?" It is a REG_EXPAND_SZ -type
> REGEDIT .reg file instead of using easy REG_SZ -type entries. The
> expansion encoded is of a variable %CYGROOT% which must be present
> in the Windows "master" environment, so that the Registry
> _always_ has access to it. I set it in my Windows9x autoexec.bat
> file of course, and under NT/2K/XP you can use the ControlPanel|System.

I was wondering why I didn't have any CYGROOT set.  I agree that
REG_EXPAND_SZ is "nicer" in terms of not hard-coding paths, but since
$CYGROOT is non-standard I don't see that it matters too much.

There's a couple of problems with it still, in the backspaces/quotes
department.  Your .reg file installs the command:

"%CYGROOT%\\bin\\bash -c \"echo -n `/bin/cygpath -u
'%l'`>/dev/clipboard\"" + NewLine

When I run the command I get an error.  The proper quoting is

"%CYGROOT%\bin\bash" -c "echo -n `/bin/cygpath -u '%l'`>/dev/clipboard"

You don't want to escape the double-quotes because they are there to
tell the windows shell to make all that stuff a single arg, after -c. 
You need double quotes around the exe image in the off chance there's a
space in $CYGROOT.  And there's the issue of the raw binary newline at
the end.  The hexified version of that is


Anyway, the Right Way (IMHO) to do this would be something like the

----- copy_cygpath.c -----
#include <sys/cygwin.h>
#include <windows.h>

int main(int argc, char **argv)
    HGLOBAL hglbBuffer;
    LPTSTR  lptstrBuffer;

    if(argc != 2) {

        // usage: copy_cygpath [win32 path]
        return 1;

    hglbBuffer = GlobalAlloc(GMEM_MOVEABLE, (MAX_PATH +
    if (hglbBuffer == NULL) {
        return 1;

    lptstrBuffer = GlobalLock(hglbBuffer);
    cygwin_conv_to_full_posix_path(argv[1], lptstrBuffer);

    if(OpenClipboard(NULL) == 0) {
        // failure!

        return 1;

    SetClipboardData(CF_TEXT, hglbBuffer);

    return 0;

$ gcc copy_cygpath.c -o copy_cygpath.exe -mwindows -luser32
$ mv copy_cygpath.exe /bin

Now your registry entry is just: 

"%CYGROOT%\bin\copy_cygpath.exe" "%1"



@="&Copy LFN Cygwin Path"


This has the advantage of loading a single process, rather than bash,
echo, and cygpath.  You also eliminate the silly console window that
flashes open and then closes.

One might also want to change the C code to backslash escape spaces and
other non-[\w\d] characters.  That way you could still work with the
long filenames at the command prompt.  Alternatively you could have it
paste the path as '/path/with a/space' (with the quotes.)


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]