Command to check cygwin info:
cygcheck -s -v -r -h
It dumps:
1. Windows system version
2. Windows system path
3. User ID
4. System directories and variables that affect cygwin
5. Environment variables when you run in cygwin
6. Cynus related registry entries
7. Mount drives
8. Cygwin entries for the mount drives.
9. List important binaries locations
10. List Cygwin DLLs' information
11. Installed cygwin services
12. Cygwin packages information
Tuesday, July 21, 2009
Binmode, textmode, cygwin, msys and grep
In the UNIX world, I guess, not many people care about the file is opened
in text mode or binary mode. In fact, most of us probably are just using
binary mode. But when it comes to the Windows world, the difference is
becoming a pain in the arse. Because in Windows, when you open a file in
text mode, every time you write a line of text, Windows makes it end with
'CRLN' instead of 'LN'. I don't intend to make a detailed explanation here
and reinvent the wheel. The best explanation is here:
http://www.cygwin.com/cygwin-ug-net/using-textbinary.html
But that link just talk about cygwin, how about MSYS. Is MSYS doing the same?
Yes, it is. By default, MSYS is in binmode. So whatever is passed in will
be pass through (the shell here I mean, including the pipes, redirected file
descriptors) untouched. So what I was trying to find out and puttting down here
is: If you run a Python program (using Windows python), the output pass through
a cygwin/msys shell (pipe), what is the end-of-line marker? My non-authorative
answer is: whatever the python program outputing and when you run the Windows
version of python, every text line is output with 'CRLN' end-of-line'.
So this is 'fine', as long as it is consistent on Windows. The thing is driving
you mad, when some programs is doing the correct thing, that is, stripping the
'\r' off the input/output lines. Which programs fall into this category, I now
find one for sure, that is grep, one of the most useful POSIX tool. The MSYS grep
will silently strip off the '\r' (CR) on each line, which the cygwin one will not.
Imagine what this will cost you! So to be safe, I decide to always use the
-U (--binary) switch.
Below is a test program to verify this. I wrote a python script:
Run it with command:
See what is the output!
Run it under MSYS with this command:
You will see it is end with 'LN'.
Now run it with this:
You will see it is end with 'CRLN'.
Try the two commands on cygwin, both have the same output.
in text mode or binary mode. In fact, most of us probably are just using
binary mode. But when it comes to the Windows world, the difference is
becoming a pain in the arse. Because in Windows, when you open a file in
text mode, every time you write a line of text, Windows makes it end with
'CRLN' instead of 'LN'. I don't intend to make a detailed explanation here
and reinvent the wheel. The best explanation is here:
http://www.cygwin.com/cygwin-ug-net/using-textbinary.html
But that link just talk about cygwin, how about MSYS. Is MSYS doing the same?
Yes, it is. By default, MSYS is in binmode. So whatever is passed in will
be pass through (the shell here I mean, including the pipes, redirected file
descriptors) untouched. So what I was trying to find out and puttting down here
is: If you run a Python program (using Windows python), the output pass through
a cygwin/msys shell (pipe), what is the end-of-line marker? My non-authorative
answer is: whatever the python program outputing and when you run the Windows
version of python, every text line is output with 'CRLN' end-of-line'.
So this is 'fine', as long as it is consistent on Windows. The thing is driving
you mad, when some programs is doing the correct thing, that is, stripping the
'\r' off the input/output lines. Which programs fall into this category, I now
find one for sure, that is grep, one of the most useful POSIX tool. The MSYS grep
will silently strip off the '\r' (CR) on each line, which the cygwin one will not.
Imagine what this will cost you! So to be safe, I decide to always use the
-U (--binary) switch.
Below is a test program to verify this. I wrote a python script:
import os
print 'hello world'
f = os.fdopen(1, 'wb', 0)
f.write('hello world\n')
f.write('hello world\r\n')
import sys
sys.stdout.close()
sys.stdout = f
print 'hello world'
Run it with command:
python test.py | xxd
See what is the output!
Run it under MSYS with this command:
python test.py | grep -v 'asdf' | xxd
You will see it is end with 'LN'.
Now run it with this:
python test.py | grep -U -v 'asdf' | xxd
You will see it is end with 'CRLN'.
Try the two commands on cygwin, both have the same output.
Labels:
carriage return,
CR,
cygwin,
end-of-line,
grep,
line feed,
LN,
msys,
Python
Thursday, July 2, 2009
Open cygwin/msys shell from Explorer window context menu
If you are a cygwin/msys user on Windows like me, you may find the
need to open a shell window from the Windows explorer. This can be
done via a context menu entry for a folder. Right-click on a folder,
and open a shell window with that folder as the current working
directory. That will be really nice, right. Windows itself also
has a toy called cmdhere, which does the
similar thing but brings up the cmd.exe window.
So how to do the cygwin/msys shell window? I search around a bit.
There are many post on the Web. But I think I settle down on this
simple one. First you need to write a bat file that take one
argument, which is the working directory. Second, you need to
modify the registry entry to add context menu for this bat file
for the folder type context menu. The bat files for my cygwin
shell is like this:
The msys version bat is like this:
Then add a new key under the "My ComputerHKEY_CLASSES_ROOT\Folder\shell"
registry entry. The new key's name can be something lik Cygwin_here/msys_here.
Then add a new key called "command" under this new entry, with the value
to be your bat file with the "%1" argument. My exported registry entry is
like these:
need to open a shell window from the Windows explorer. This can be
done via a context menu entry for a folder. Right-click on a folder,
and open a shell window with that folder as the current working
directory. That will be really nice, right. Windows itself also
has a toy called cmdhere, which does the
similar thing but brings up the cmd.exe window.
So how to do the cygwin/msys shell window? I search around a bit.
There are many post on the Web. But I think I settle down on this
simple one. First you need to write a bat file that take one
argument, which is the working directory. Second, you need to
modify the registry entry to add context menu for this bat file
for the folder type context menu. The bat files for my cygwin
shell is like this:
@echo off
start /min C:\cygwin\bin\bash --login -i -c 'cd "`cygpath %1`"; rxvt +sb +vb '
The msys version bat is like this:
@echo off
start /min C:\cygwin\bin\bash --login -i -c 'cd "`cygpath %1`"; rxvt +sb +vb '
Then add a new key under the "My ComputerHKEY_CLASSES_ROOT\Folder\shell"
registry entry. The new key's name can be something lik Cygwin_here/msys_here.
Then add a new key called "command" under this new entry, with the value
to be your bat file with the "%1" argument. My exported registry entry is
like these:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Folder\shell\Cygwin_Here]
@="Cygwin Here"
[HKEY_CLASSES_ROOT\Folder\shell\Cygwin_Here\command]
@="C:\\cygwin\\rxvt_here \"%1\""
[HKEY_CLASSES_ROOT\Folder\shell\Msys_Here]
[HKEY_CLASSES_ROOT\Folder\shell\Msys_Here\command]
@="c:\\msys\\1.0\\msys_here \"%1\""
Subscribe to:
Posts (Atom)