How to run any windows program from cygwin, still using cygwin-style path

In my previous post I posted a script useful for running kdiff3 for windows correctly from within cygwin. Here’s a more general version that can be used for any windows program. Save the following as ~/ (or whatever you like):

for arg
if [[ "" != "$arg" ]] && [[ -e $arg ]];
OUT=`cygpath -wa $arg`
if [[ $arg == -* ]];
echo "$RESULT"

The script tries to find any file or directory names in your command line arguments, and converts them to absolute, windows-style path names using cygpath -wa. You can then run something like:

explorer `~/ /tmp`

And it will open Windows Explorer in the correct folder.

Also, the script to run kdiff3 becomes (just replace the path to the executable with your own):

"/cygdrive/d/Program Files (x86)/KDiff3/kdiff3.exe" `~/ "$@"`

How to run any windows program from cygwin, still using cygwin-style path

7 thoughts on “How to run any windows program from cygwin, still using cygwin-style path

  1. djf says:

    I use a similar script but I avoid the backticks by including the running of the command in the script, so it’s like this: some/windows/prog.exe /home/whatever /tmp/foo

    I think it’s easier to type this way. You do lose tab-completion of the exe name if you don’t type it first, although that might be fixable in bash somehow.

  2. Great tip! Thanks !

    I still just need to find a way to copy from GNU Emacs (and maybe mintty) to Windows apps without the mouse and I will be able to work in Windows when necessary, without waving my hands all day long!



  3. Michael Sandler says:

    I wrote a script to help fix some of the annoying issues with windows and cygwin (paths) interaction

    makewin() {
    eval “function $1 {
    # Don’t taint locals
    local FN
    declare -a FN
    local x
    # For each option
    for x in \”\${@}\”
    # Fix the path to “windows”
    FN[\”\${#FN[*]}\”]=\`cygpath -w \”\$x\”|sed ‘s/ /\\\\ /g’\`

    # Run the Command
    \”$2\” \”\${FN[@]}\” >/dev/null 2>/dev/null &
    Then I run it for each command I want to fix

    makewin vi /cygdrive/c/Program\ Files\ \(x86\)/Vim/vim74/gvim.exe
    makewin np /cygdrive/c/Program\ Files\ \(x86\)/Notepad++/notepad++.exe

    It creates a function alias to the command I want that fixes the parameter path issues. This is added to my ~/.bash_profile

  4. The kdiff3 solution doesn’t seem to work unfortunately. The file paths in arguments have “(working copy)”, “(revision xxx)” appended to them which seem to break the cygwinify script. It does not convert the paths with those appendixes.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s