Dos paths and unix paths conversion


  1. Posts : 33
    win 7 home premium
       #1

    Dos paths and unix paths conversion


    I guess this may be a tiny bit off the subject here, but I am attempting this in windows 7.

    I have a program file manager tool called 'Directory Opus' that is capable of calling windows external programs and passing them the current directory the file manager is sitting on.

    So far so good.

    Now I want to call a cygwin (linux/unix emulator for windows) terminal with that file manager.

    Checking properties on the cygwin Icon I got the path: C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -

    So it is a path to a command and an argument to that command.

    Actually I guess it is 2 arguments to a command since I think '-' in that position means to feed anything on STDIN to the command. At least that would be true in unix shell programming.

    So using the Directory opus setup I pass this call:
    '@async:C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico - <and here add {s}>'

    So the call ends up:
    '@async:C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico - {s}'

    That call does just what it is supposed to. It passed the current file absolute address however cygwin terminal does not understand the windows path notation. If I were passing it: C:\subdir\blah\ It would just say 'No such file' Cygwin terminal wants to see /cygdrive/c/subdir/blah Or at least I think that is what is happing.

    So to cut to the chase.... I'd like to put a little wrapper to Cygwin terminal in there with the code necessary to convert 'C:\subdir\blah\' to '/cygdrive/c/subdir/blah/'

    But, I do not know how to code up such a *.bat file. To do it in linux shell languages would be (for me) something I could do but it would take some trial and error. But when it comes to dos shell language... I don't know poop.

    Can I get any takers on coaching me thru the required coding.... Yes, I know, it could be a bit time consuming considering I am known to be a bit thick skulled at times. But..., so, any takers?
      My Computer


  2. Posts : 5,092
    Windows 7 32 bit
       #2

    I would ask on DonationCoder.com specifically this forum:
    General Software Discussion - DonationCoder.com

    The reason is I know there are a bunch of DO aficionados, who also use Linux, on that forum. I've never tried DO myself. I have played around with CygWin. But it's been a few years. :)

    If the site wants a donation to sign up just explain to Mouser why you want to post etc.. I think he'll be sympathetic. :)
      My Computer


  3. Posts : 318
    Windows 10 x64
       #3

    If you're trying to run a program or shell script, use this:

    Here I'm running a shell script under bash, and I'm giving it a Windows type of path, as C:\ ... and then I invoke cygpath -m to convert it to a mixed C:/ format (which keeps the bash shell happy). Take note of the single quotes.
    C:\cygwin\bin\mintty.exe C:/cygwin/bin/bash.exe $(cygpath -m 'C:\blah\blah\script')
    (You could instead convert to a Unix /cygdrive/c/ type of path using cygpath -u)

    Now if you want to use your file manager, and point to a file, and use the right-click context menu to run that program/script in a shell ... I handle that with a special script and a registry modification.

    Here's the registry mod:
    REGEDIT4

    [HKEY_CLASSES_ROOT\*\shell\Run under bash]
    @="Run under bash"

    [HKEY_CLASSES_ROOT\*\shell\Run under bash]
    @="C:\\cygwin\\bin\\mintty.exe C:\\cygwin\\bin\\bash.exe C:/blah/path/runshellscript \"%1\""


    With
    that in place you can right click on any script, select "Run under bash" and it will run ... with the help of this script called runshellscript located in the above-named C:/blah/path directory of your choice ...

    # runshellscript

    # Set your PATH here!
    # Otherwise you'll have no PATH at all!
    #PATH="blah:blah:blah"
    #export PATH

    # Or you might want to source some "standard" profile stuff to get the PATH ...
    . /etc/profile
    . $HOME/.bash_profile

    item="$1"
    if [ "$item" = "" ] ; then
    exit 1
    fi

    # Convert to Unix path format
    object=$(cygpath -u "$item")

    # Cannot "run" a directory ...
    if [ -d "$object" ] ; then
    exit 1
    fi

    # Get the directory in which the script resides
    dir=$(dirname "$object")

    # Get the name of the script
    base=$(basename "$object")

    # Go to that directory
    cd "$dir"

    # Run the script
    ./$base

    exit 0


    But be careful. The registry mod will allow you to run ANY file as a shell script. It might be better to only run script files that have a .sh suffix. In that case, alter the registry mod by substuting .sh for the * asterisk.

      My Computer


  4. Posts : 5,092
    Windows 7 32 bit
       #4

    Also depending what you need to do, these win32 stand-alones can be very handy:
    GnuWin32 Packages
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 02:16.
Find Us