最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】尝试给右键打开Cygwin的mintty中加上log文件功能

Cygwin crifan 4048浏览 0评论

【背景】

之前,已经实现了右键打开Cygwin的功能:

【整理】在windows下添加右键使得可以运行cygwin且直接定位到当前文件夹 + 【整理】如何在Windows XP中,右键添加命令行cmd command,打开当前文件夹,定位到当前路径

【基本解决】恢复使用mintty作为Cygwin的默认(终端)窗口工具,即添加右键(调用Mintty)打开Cygwin的功能

【已解决】为docbook环境而去添加右键运行cygwin

现在,后来得知mintty的-l参数是支持log文件的:

Administrator@PC-20130611GART /home/develop/crosstool-ng/crosstool-ng-1.18.0_build
$ mintty --help
Usage: mintty [OPTION]... [ PROGRAM [ARG]... | - ]

Start a new terminal session running the specified program or the user's shell.
If a dash is given instead of a program, invoke the shell as a login shell.

Options:
  -c, --config FILE     Load specified config file
  -e, --exec            Treat remaining arguments as the command to execute
  -h, --hold never|start|error|always  Keep window open after command finishes
  -i, --icon FILE[,IX]  Load window icon from file, optionally with index
  -l, --log FILE|-      Log output to file or stdout
  -o, --option OPT=VAL  Override config file option with given value
  -p, --position X,Y    Open window at specified coordinates
  -s, --size COLS,ROWS  Set screen size in characters
  -t, --title TITLE     Set window title (default: the invoked command)
  -u, --utmp            Create a utmp entry
  -w, --window normal|min|max|full|hide  Set initial window state
      --class CLASS     Set window class name (default: mintty)
  -H, --help            Display help and exit
  -V, --version         Print version information and exit

所以想要实现:

右键打开Cygwin后,不仅仅调用mintty打开终端

且可以支持传入对应的log文件参数,文件名是当前日期时间的。

【解决过程】

1.先去研究:

【记录】cygwin下通过Linux命令得到当前时间且输出为特定格式

2.然后再去,研究,然后去把参数加进来。

查到之前的,添加的注册表是:

E:\dev_install_root\cygwin\bin\mintty.exe -e E:\dev_install_root\cygwin\bin\bash -c "/bin/xhere /bin/bash.exe '%L'"

然后,尝试修改。

3.先去试试,在cmd下,运行mintty,且给定log参数,看看是否可行。

结果说明,是可以的:

cmd run mintty give log file

对应会跳出对应的cygwin的mintty窗口,然后随便试了试一些命令:

cygwin mintty run some command

对应的log文件内容也是正常的:

log file is ok for mintty

3.然后再去试试cmd中,能否用上对应的date而得到当前的日期时间。

直接运行是可以的:

C:\Users\Administrator.PC-20130611GART>E:\dev_install_root\cygwin\bin\date.exe +%Y%m%d_%H%M%S
20130906_224844

4.看看能否传递到mintty中:

【记录】尝试让windows中的cmd中一个命令的输出作为另外一个命令的输入且是传递到参数中间的

结果是没法传递过来。。。。

 

【总结】

最终的办法是:

【记录】尝试让windows中的cmd中一个命令的输出作为另外一个命令的输入且是传递到参数中间的

最后记录的:


去注册表中,将:

HKEY_CLASSES_ROOT\Directory\shell\RunCygwin\command

值设置为:

E:\dev_install_root\cygwin\bin\mintty.exe --log=E:\dev_install_root\cygwin\home\log\cygwin_mintty_log.txt -e E:\dev_install_root\cygwin\bin\bash -c "/bin/xhere /bin/bash.exe '%L'"

如图:

runcygwin command value include mintty log para

就可以实现:

每次右键任意一个文件夹,选择RunCygwin,然后就

  • 调用mintty打开cygwin了;
  • 且定位到当前文件夹。
  • 且清空对应的log文件:E:\dev_install_root\cygwin\home\log\cygwin_mintty_log.txt
  • 且接下来的,所有的cygwin窗口的输出的内容,都自动保存到该log文件中;

注意:

如果另外再(通过右击选择RunCygwin或者独立打开Cygwin),都会导致清空该log文件,即,该log文件,只能记录最后一个打开的Cygwin的mintty的输出的内容

附上一个效果图:

(1)右击某文件夹,选择RunCygwin:

some folder right click runcygwin

(2)可以打开mintty,且以定位到当前文件夹,然后随便使用一些命令,得到一些输出,然后对应的log文件中,可以看到对应的输出:

can use log file record mintty output

 

最后附上导出的注册表内容:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\RunCygwin\command]
@="E:\\dev_install_root\\cygwin\\bin\\mintty.exe --log=E:\\dev_install_root\\cygwin\\home\\log\\cygwin_mintty_log.txt -e E:\\dev_install_root\\cygwin\\bin\\bash -c \"/bin/xhere /bin/bash.exe '%L'\""

需要的自己另存为

runCygwin_WithMinttyLogFile.reg

然后双击运行即可。

转载请注明:在路上 » 【记录】尝试给右键打开Cygwin的mintty中加上log文件功能

与本文相关的文章

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.192 seconds, using 22.32MB memory