Dos paths and unix paths conversion

HarryPutnam

New member
Local time
3:32 PM
Messages
33
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

Computer Manufacturer/Model Number
Sager Laptop running win 7 Home Premium
OS
win 7 home premium
CPU
i7 820 quad 1.73 Ghz
Memory
8 GB
Graphics Card(s)
ATI Radeon HD 5800 (1 GB)
Sound Card
Built in (Realtek HD Audio)
Monitor(s) Displays
(Laptop integral) ??
Hard Drives
2 WD SATA 500 GB
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

Computer Manufacturer/Model Number
HP Media Center
OS
Windows 7 32 bit
CPU
AMD 5200+ dual core
Memory
2 GB
Graphics Card(s)
NVidia GeForce 6150SE 128 MB
Monitor(s) Displays
CRT
Screen Resolution
1280x1024
Hard Drives
500 GB Sata internal :

SIIG USB 3.0 docking stations w/WD Caviar Black 6 Gb/s drives
Keyboard
PS/2
Mouse
PS/2 Wheel Mouse
Other Info
SIIG USB 3.0 PCIexpress card.
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

Computer type
PC/Desktop
Computer Manufacturer/Model Number
Dell
OS
Windows 10 x64
CPU
i7-7700K
Memory
16 GB 2400 MHz
Graphics Card(s)
GTX 1060
Sound Card
Integrated, plus external Presonus Audiobox USB
Monitor(s) Displays
2x AOC 27"
Screen Resolution
1920x1080
Hard Drives
512 GB M.2 SSD
2 TB 7200 RPM disk
Internet Speed
110 Mbps
Browser
Firefox
Also depending what you need to do, these win32 stand-alones can be very handy:
GnuWin32 Packages
 

My Computer

Computer Manufacturer/Model Number
HP Media Center
OS
Windows 7 32 bit
CPU
AMD 5200+ dual core
Memory
2 GB
Graphics Card(s)
NVidia GeForce 6150SE 128 MB
Monitor(s) Displays
CRT
Screen Resolution
1280x1024
Hard Drives
500 GB Sata internal :

SIIG USB 3.0 docking stations w/WD Caviar Black 6 Gb/s drives
Keyboard
PS/2
Mouse
PS/2 Wheel Mouse
Other Info
SIIG USB 3.0 PCIexpress card.
Back
Top