|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『楼 主』:
被一个 Wimc 低级 BUG 郁闷N天
使用 LLM 解释/回答一下
@echo off
set keyname=微软真垃圾
set /p=%keyname%<nul>name.txt
wmic /?
pause
BUG症状光标闪烁批处理被中断,环境WinXP SP2,我原来的批处理代码很长,挖出这个臭虫用了N天,本以为代码某部分不稳定,原来被这个低级臭虫整了,真郁闷~
大家以后注意 set /p= <nul>name.txt和wmic在同一批处理中使用
@echo off
set keyname=微软真垃圾
set /p=%keyname%<nul>name.txt
wmic /?
pause
BUG symptom: cursor flashes and batch is interrupted. Environment: WinXP SP2. My original batch code was very long, and it took me days to dig out this bug. I thought some part of the code was unstable, but it turned out to be this low-level bug. Really depressed~
Everyone, please pay attention to using set /p= <nul>name.txt and wmic in the same batch in the future
此帖被 +2 点积分 点击查看详情 评分人:【 vkill 】 | 分数: +2 | 时间:2008-1-22 13:51 |
|
|

第一高手 第二高手
我的小站
 |
|
2008-1-20 19:06 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
你工作目录下应新生成了一个批处理吧?
There should be a newly generated batch file in your working directory, right?
|
|
2008-1-21 01:20 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
set /p=%keyname%<nul>name.txt
跟上copy con file与more也是这种情况,不过wmic会将输入当成一个脚本
set /p=%keyname%<nul>name.txt
The same situation applies to following copy con file and more, but wmic will treat the input as a script
|
|
2008-1-21 01:25 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
当前目录没生成批处理。
本来只是用set/p生成一个不带换行符的文本,没想到此后wmic任何参数不起作用了。
The batch file was not generated in the current directory.
I originally just wanted to use set/p to generate a text without a newline character, but I didn't expect that then no parameters of wmic would work.
|

第一高手 第二高手
我的小站
 |
|
2008-1-21 12:47 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
解决方法
@echo off
set keyname=微软真垃圾
set /p=%keyname%<nul>name.txt
set /p=<nul>nul
wmic /?
pause
Solution
```batch
@echo off
set keyname=微软真垃圾
set /p=%keyname%<nul>name.txt
set /p=<nul>nul
wmic /?
pause
```
|

第一高手 第二高手
我的小站
 |
|
2008-1-21 12:58 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
看来问题还是出在set/p参数方面
@echo off
set keyname=微软真垃圾
>name.txt set/p=%keyname%<nul
wmic /?
pause
It seems the problem is still with the set/p parameter.
@echo off
set keyname=Microsoft is really rubbish
>name.txt set/p=%keyname%<nul
wmic /?
pause
|

第一高手 第二高手
我的小站
 |
|
2008-1-21 13:52 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Originally posted by fastslz at 2008-1-21 12:47 PM:
当前目录没生成批处理。
本来只是用set/p生成一个不带换行符的文本,没想到此后wmic任何参数不起作用了。
不是不启作用了,而是几次重定向后不知为何激活了wmic打控制台获取输入
你可以在命令行下输入然后以ctrl+z终止就会产生一个wmic的临时性脚本文件
只要有打控制台接收数据功能的命令都会在这样的批处理下产生这样的错误
按你的批处理我觉得有这种功能的命令都有一个潜在的句柄,这个句柄是命令自定义的,主要来完成管道传输
Originally posted by fastslz at 2008-1-21 12:47 PM:
No batch file was generated in the current directory.
I originally just wanted to use set/p to generate a text without line breaks, but unexpectedly, wmic didn't work with any parameters after that.
It's not that it didn't work, but after several redirections, for some reason, it activated the console input acquisition of wmic.
You can enter at the command line and terminate with ctrl+z to generate a temporary script file for wmic.
Any command that has the function of receiving data in the console will have such an error in such a batch file.
According to your batch file, I think any command with this function has a potential handle, which is customized by the command and mainly used to complete pipeline transmission.
|
|
2008-1-22 13:28 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
这样也可以啊
@echo off
set keyname=微软真垃圾
>name.txt set /p=%keyname%<nul
wmic /?
pause
所以我写>file时都把>写在前面
This is also okay
@echo off
set keyname=微软真垃圾
>name.txt set /p=%keyname%<nul
wmic /?
pause
So when I write >file, I put > at the front
|
|
2008-1-22 13:50 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
楼主的精神值得鼓励
The spirit of the original poster is worthy of encouragement
|
|
2008-1-22 13:51 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
我在一个批处理中使用下面代码获取磁盘空间
wmic logicaldisk get DeviceID,FreeSpace,Size | findstr "%_Drives%"
但是发现程序某些时刻运行时会失去响应
此时在当前命令行下直接运行以下代码也会失去响应
wmic logicaldisk get DeviceID,FreeSpace,Size
在输入一个Ctrl+Z和一个回车后会继续输出执行结果
此时会在当前路径下产生一个零字节的文件
TempWmicBatchFile.bat
此时另开一个命令行环境
当前路径相同
执行此代码无问题
与此相关的问题也出现使用脚本操作diskpart列磁盘分区时
此时只能Ctrl+Break终止代码执行
怀疑是这些命令在执行时会锁定一些卷
而如果在这些命令上使用管道
而命令的管道管道需要在%TMP%产生临时文件
而如果%TMP%所在卷恰被锁定
则临时文件无法建立在这个卷上建立
管道操作就无法完成
管道后的命令输入被转向控制台
而输入Ctrl+Z加回车后正是结束控制台输入
当然目前为止这只是猜测……
这是我在另一篇主题帖的发言
是在没有看此主题之前
现在综合两个主题的讨论
我觉得很像是自定义句柄的问题
也即是说wmic很可能使用了3-9中的某个自定义句柄
而此时如果使用set /p,copy con或者管道操作时
会有很大概率将这个自定义句柄“污染”
导致wmic的输入被转向控制台
而且这样的“污染”是在一个命令行会话中全局有效的
与此相关的讨论见
http://www.cn-dos.net/forum/viewthread.php?tid=16942
Last edited by qzwqzw on 2008-1-24 at 08:36 PM ]
I used the following code in a batch file to get disk space:
wmic logicaldisk get DeviceID,FreeSpace,Size | findstr "%_Drives%"
But I found that the program would become unresponsive at some moments.
At this time, directly running the following code in the current command line would also become unresponsive:
wmic logicaldisk get DeviceID,FreeSpace,Size
After entering a Ctrl+Z and a carriage return, the execution result would continue to be output.
At this time, a zero-byte file named TempWmicBatchFile.bat would be generated in the current path.
Open another command line environment, with the same current path, and executing this code would be fine.
A related problem also occurs when using scripts to operate diskpart to list disk partitions. At this time, only Ctrl+Break can be used to terminate the code execution.
Suspect that these commands may lock some volumes when executing.
And if pipes are used on these commands, and the pipe of the command needs to generate a temporary file in %TMP%, and if the volume where %TMP% is located is locked, the temporary file cannot be created on this volume, and the pipe operation cannot be completed. The input after the pipe is redirected to the console, and entering Ctrl+Z plus carriage return is exactly to end the console input.
Of course, this is just a guess so far...
This is my post in another thread before I saw this topic.
Now, after integrating the discussions of the two topics, I think it is very likely related to the problem of custom handles. That is to say, wmic may be using one of the custom handles from 3 to 9. And at this time, if set /p, copy con or pipe operations are used, there is a high probability that this custom handle will be "polluted", causing the input of wmic to be redirected to the console. And such "pollution" is globally effective in one command line session.
The related discussion is as follows:
http://www.cn-dos.net/forum/viewthread.php?tid=16942
Last edited by qzwqzw on 2008-1-24 at 08:36 PM ]
|
|
2008-1-24 20:34 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
everest79也说了会产生一个临时文件的,而我这里没发现临时文件,看来是另一种“句柄污染”wmic对管道符特别敏感
everest79 also said that a temporary file would be generated, but I didn't find the temporary file here. It seems to be another kind of "handle pollution". Wmic is particularly sensitive to pipe characters
|

第一高手 第二高手
我的小站
 |
|
2008-1-24 20:40 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
这样就可以继续
@echo off
set keyname=微软真垃圾
set /p=%keyname%<nul>name.txt
START wmic /?
This can continue
@echo off
set keyname=Microsoft is really rubbish
set /p=%keyname%<nul>name.txt
START wmic /?
|

简单!简单!再简单! |
|
2008-1-24 21:02 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
@echo off
s<nul>nul
echo test
wmic /?
pause
这样的代码说明问题与set /p无关
而是与代码中出现的两个重定向符号<和>有关
这与http://www.cn-dos.net/forum/viewthread.php?tid=16942中的讨论就对应的上了
12楼的start是新开了命令行会话
问题自然可以解决
但通常意义不大
因为我们很难把wmic的输出传回至原命令行会话
Last edited by qzwqzw on 2008-1-24 at 09:16 PM ]
```
@echo off
s<nul>nul
echo test
wmic /?
pause
```
Such code shows that the problem is not related to set /p, but related to the two redirection symbols < and > that appear in the code. This corresponds to the discussion in http://www.cn-dos.net/forum/viewthread.php?tid=16942. The start in floor 12 is a new command line session, and the problem can naturally be solved. But usually it is of little significance because it is difficult for us to transfer the output of wmic back to the original command line session.
Last edited by qzwqzw on 2008-1-24 at 09:16 PM ]
|
|
2008-1-24 21:12 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
从6楼可以看出
@echo off
>nul s<nul
echo test
wmic /?
pause
这样重定向就不会出现这样的情况
It can be seen from floor 6
@echo off
>nul s<nul
echo test
wmic /?
pause
In this way, redirection will not have such a situation
|

第一高手 第二高手
我的小站
 |
|
2008-1-24 21:29 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
具体的原因肯定与WMIC内部的处理机制有关
从那个TempWmicBatchFile.bat可以看出其中的端倪
不过无论如何
我们不能因为wmic而不使用<nul>nul的句式
所以使用下面的方法应该在批处理中有效的
wmic /?<nul
或者
cd.|wmic /?
这样不用管脚本前面使用了那些自定义句柄
都保证wmic所用的都是一致的
但是在命令行下运行cd.|wmic /?提示
Win32 错误: 另一个程序正在使用此文件,进程无法访问。
很有意思的提示!
The specific reason must be related to the internal processing mechanism of WMIC. We can see some clues from that TempWmicBatchFile.bat. However, no matter what, we can't stop using the <nul>nul sentence pattern because of WMIC. So the following methods should be effective in batch processing: wmic /?<nul or cd.|wmic /? In this way, no matter what custom handles were used in front of the script, it ensures that what WMIC uses is consistent. But when running cd.|wmic /? in the command line, it prompts: Win32 error: The file is being used by another process, and the process cannot access it. What an interesting prompt!
|
|
2008-1-24 22:36 |
|