VBS隐藏窗口运行Cygwin Bash内置命令/函数的方法(主要供Windows任务计划调用使用)
2022/4/22 7:12:41
本文主要是介绍VBS隐藏窗口运行Cygwin Bash内置命令/函数的方法(主要供Windows任务计划调用使用),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
File:bash-hide.vbs
Dim Wsh,ScriptPath,CygwinInstallPath,CygwinInstallDrive,BashPath,ArgumentParamter ArgumentParamter="" 'Wscript.Echo "参数个数:" & Wscript.Arguments.Count IF Wscript.Arguments.Count >0 Then For i=0 To Wscript.Arguments.Count-1 ArgumentParamter=ArgumentParamter & Space(1) & Wscript.Arguments(i) Next End If 'Msgbox ArgumentParamter 'Wscript.Quit Set Fso=CreateObject("Scripting.FileSystemObject") ScriptPath=Fso.GetFile(Wscript.ScriptFullName).ParentFolder.Path Set Conf=Fso.OpenTextFile(ScriptPath & "\cygwin_installion_path.txt",1,false) CygwinInstallPath=Conf.ReadAll() Set Folder=Fso.GetFolder(CygwinInstallPath) CygwinInstallDrive=Folder.Drive BashPath=CygwinInstallDrive & "\cygwin64\bin\bash.exe" 'Wscript.Echo BashPath & " --login -i -c '" & ArgumentParamter & ";bash'" Set Wsh=CreateObject("Wscript.Shell") '注意:如果参数中含有中文,则必须在UTF-8的窗口中运行命令,比如在Cygwin窗口中执行 wscript //nologo bash-hide.vbs potplayertv 湖南卫视 '否则会报错,比如原生cmd窗口默认为 chcp 936编码,带中文参数调用此脚本就达不到预期的效果 Wsh.run BashPath & " --login -i -c '" & ArgumentParamter & "'",vbHide '保持窗口可见,且不自动退出 'Wsh.run BashPath & " --login -i -c '" & ArgumentParamter & ";bash'"
其中cygwin_installion_path.txt
文件保存Cygwin的安装路径(纯文本),eg:H:\cygwin64
,以适配不同电脑 Cygwin 安装在不同位置的情况;
在 Cygwin 窗口中调用bash-hide.vbs
若要在Cygwin窗口中直接调用 bash-hide.vbs xxx
命令,建议在会话配置文件(~/.bash_profile
)中装载以下函数:
bash-hide.vbs() { #劫持bash-hide.vbs命令,使用wscript调用之 #详见: D:\Extra_bin\bash-hide.vbs #Bash窗口隐藏 #调用时可传递环境变量依然有效,比如: # _T='E:\' bash-hide.vbs cygwin #在指定目录打开全新Cygwin窗口 cygstart bash-hide.vbs $@ } bash-run.vbs() { #劫持bash-run.vbs命令,使用wscript调用之 #详见: D:\Extra_bin\bash-run.vbs #bash窗口可见 cygstart bash-run.vbs $@ }
Windows任务计划调用示例:
这篇关于VBS隐藏窗口运行Cygwin Bash内置命令/函数的方法(主要供Windows任务计划调用使用)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15PingCAP 黄东旭参与 CCF 秀湖会议,共探开源教育未来
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升