Board logo

标题: [其他] 多线程执行批处理脚本 cocmd 1.2 [打印本页]

作者: Byaidu    时间: 2021-9-7 06:55     标题: 多线程执行批处理脚本 cocmd 1.2

本帖最后由 Byaidu 于 2021-9-7 06:59 编辑

cocmd 工具通过在进程空间中加载多个 cmd.dll 实例实现了真正意义上的多线程执行批处理脚本

使用方法:cocmd [命令1] [命令2] ...

不同于 start /b 的多进程启动方式,因为环境变量和进程环境是绑定的,所以多个脚本线程间可以实时共享变量以及 GDI 句柄等资源

1.2 版本添加了线程锁机制并集成了 CAPIx 的强大功能

多线程机制可以很大程度上提升批处理脚本的可玩性

例如通过多线程机制可以实现一个简单的实时聊天室,网络通信、用户输入以及界面绘制等功能可以通过 CAPIx 实现,并借助 cocmd 分离到不同的线程执行,线程之间可以通过变量实时通讯而不会相互干扰

项目地址:https://github.com/Byaidu/cocmd
作者: peterboy666    时间: 2021-9-7 14:40

从你的下载点 测 V1.3

OS: Windows 7 X64 繁体中文版

运行 V1.3 内的 test.bat

A.
1.bat 并没得到正确的结果
title time:%time%(1.bat) a:%a%(2.bat) b:%b%(3.bat)

B.
仍然有错误

系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 0
2.bat 0
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 1
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 1
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 2
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
1.bat lock
3.bat 2
3.bat 3
3.bat 4
1.bat unlock
2.bat 4
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 5
2.bat 5
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 6
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 6
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 7
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 7
2.bat 8
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 9
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 8
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 10
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 9
2.bat 11
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 12
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 10
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 13
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
3.bat 11
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 14
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
系统在 System 的讯息档中找不到讯息编号 0x8 的讯息文字。
2.bat 15
作者: Byaidu    时间: 2021-9-7 15:09

回复 2# peterboy666


我这里是 Windows 7 SP1 X64 简体中文,可以正确显示 title


作者: Byaidu    时间: 2021-9-7 15:33

回复 2# peterboy666


https://github.com/Byaidu/cocmd/archive/refs/tags/v1.3.zip
作者: Byaidu    时间: 2021-9-7 15:43

回复 2# peterboy666


可能是系统版本问题导致 1.bat 没有正常启动

把 test.bat 的内容改成 cocmd "" "" test\1.bat test\2.bat test\3.bat 应该就可以了
作者: peterboy666    时间: 2021-9-7 16:32

本帖最后由 peterboy666 于 2021-9-7 16:37 编辑

回复 4# Byaidu

3F
>我这里是 Windows 7 SP1 X64 简体中文,可以正确显示 title
原来你运行也报错,
你要不要修一下.

4F
>https://github.com/Byaidu/cocmd/archive/refs/tags/v1.3.zip
比对  HASH 一模一样.

5F
>可能是系统版本问题导致 1.bat 没有正常启动
>把 test.bat 的内容改成 cocmd "" "" test\1.bat test\2.bat test\3.bat 应该就可以了
一样 1.bat 没正常启动
顯示
C:\windows\system32\cmd.exe - test\1.bat - test\2.bat - test\3.bat
作者: Byaidu    时间: 2021-9-7 17:55

回复 6# peterboy666


那个报错的问题好修,直接 hook 屏蔽掉 PutMsg 就可以

但是不能执行 title 就有点奇怪了,我这边没办法复现的话就不太好改,不过好像也不是什么大问题(
作者: Byaidu    时间: 2021-9-7 18:05

本帖最后由 Byaidu 于 2021-9-7 18:22 编辑

回复 6# peterboy666


github 上发布了 1.5 版本,现在应该没有报错了
作者: peterboy666    时间: 2021-9-7 18:57

本帖最后由 peterboy666 于 2021-9-7 19:03 编辑

回复 8# Byaidu



1.
已不报错.

2.
1.bat
title time:%time%(1.bat) a:%a%(2.bat) b:%b%(3.bat)
还是没有动作.

3.
我将
title time:%time%(1.bat) a:%a%(2.bat) b:%b%(3.bat)
改成
echo time:%time%(1.bat) a:%a%(2.bat) b:%b%(3.bat)
就有动作了.

4.
但运行结果,
只有 5 次 time,

只有 28 次 time,
之后就没有再出现 time 这很奇怪 ?

运行结果:

time:18:52:44.50(1.bat) a:0(2.bat) b:0(3.bat)
#2.bat 0
#3.bat 0
time:18:52:45.65(1.bat) a:1(2.bat) b:1(3.bat)
#2.bat 1
time:18:52:46.73(1.bat) a:2(2.bat) b:1(3.bat)
#3.bat 1
time:18:52:47.82(1.bat) a:2(2.bat) b:2(3.bat)
#2.bat 2
time:18:52:48.90(1.bat) a:3(2.bat) b:2(3.bat)
#1.bat lock
#3.bat 2
#3.bat 3
#3.bat 4
#1.bat unlock
#2.bat 4
#2.bat 5
#3.bat 5
#2.bat 6
#3.bat 6
#2.bat 7
#3.bat 7
#2.bat 8
#2.bat 9
#3.bat 8
#2.bat 10
#3.bat 9
#2.bat 11
#2.bat 12
#3.bat 10
#2.bat 13
#3.bat 11
#2.bat 14
#2.bat 15
#3.bat 12
#2.bat 16
#3.bat 13
#2.bat 17
#2.bat 18
#3.bat 14
#2.bat 19
#3.bat 15
#2.bat 20
作者: Byaidu    时间: 2021-9-8 09:13

回复 9# peterboy666


原生的 cmd 对并行操作支持不太好,有时候会把管道描述符卡错位导致不能正常输出,如果有输出字符的需求可以使用内置的 CAPIx 调用 WriteConsoleOutputCharacter 完成




欢迎光临 批处理之家 (http://bathome.net./) Powered by Discuz! 7.2