Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.

Windows 7: Dos paths and unix paths conversion

03 Mar 2014   #1

win 7 home premium
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 System SpecsSystem Spec
03 Mar 2014   #2

Windows 7 32 bit

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

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 System SpecsSystem Spec
03 Mar 2014   #3

Windows 10 x64

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:

[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\""

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!
#export PATH

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

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

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

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

# 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

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 System SpecsSystem Spec

04 Mar 2014   #4

Windows 7 32 bit

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

 Dos paths and unix paths conversion

Thread Tools

Similar help and support threads
Thread Forum
Need to fix folder Paths.
I did not know which forum to post in for my problem. Sorry if this is the wrong one. :D I recently tried to relocate my data folders and something went wrong. When I was done I had dble folders. This is a picture of the results. I moved them back to it's original place. I want to be...
BSOD Help and Support
Help With File Paths
Hello, I know (am pretty sure >.<) that there is a way to do this. I am trying to set a file path for a folder, but I need the folder to go to the current username, instead of my username. For example.. C:\Users\Matt\Documents\ - Is my current path I want it to be C:\Users\*THEIR USER...
General Discussion
Folder paths
I noticed that several programs are having problems linking to files in the My pictures folder. Adobe Photoshop Album (needed inorder to clean out and move on to new software) and a program called 7stacks (an icon link problem) are trying to link to the My pictures folder. They seem to be coded...
Music, Pictures & Video
Paths , Librabries ?
Is it possib to delete the shared document and libraries from my Seven ? Or will windows keep generating new ones at each boot ? Can I stop windows from doing this ? or have i have to live with this ? PC-specs Packard Bell Imedia q8400 4 gb ram etc
Network & Sharing
Win7 Upgrade paths
From this download link: Unsupported Upgrade Scenarios Upgrades to Windows 7 from the following operating systems are not supported: Windows 95, Windows...
General Discussion

Our Sites

Site Links

About Us

Find 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 03:54.
Twitter Facebook Google+