China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-07 09:23
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Been depressed for several days by a low-level Wimc bug View 3,486 Replies 17
Original Poster Posted 2008-01-20 19:06 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline

@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
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
vkill +2 2008-01-22 13:51
第一高手 第二高手

Floor 2 Posted 2008-01-21 01:20 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
There should be a newly generated batch file in your working directory, right?
Floor 3 Posted 2008-01-21 01:25 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
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
Floor 4 Posted 2008-01-21 12:47 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
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.
第一高手 第二高手

Floor 5 Posted 2008-01-21 12:58 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
Solution
```batch
@echo off
set keyname=微软真垃圾
set /p=%keyname%<nul>name.txt
set /p=<nul>nul
wmic /?
pause
```
第一高手 第二高手

Floor 6 Posted 2008-01-21 13:52 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
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
第一高手 第二高手

Floor 7 Posted 2008-01-22 13:28 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
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.
Floor 8 Posted 2008-01-22 13:50 ·  中国 青海 西宁 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
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
Floor 9 Posted 2008-01-22 13:51 ·  中国 青海 西宁 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
The spirit of the original poster is worthy of encouragement
Floor 10 Posted 2008-01-24 20:34 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline

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 ]
Floor 11 Posted 2008-01-24 20:40 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
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
第一高手 第二高手

Floor 12 Posted 2008-01-24 21:02 ·  中国 江苏 常州 溧阳市 电信
银牌会员
★★★
Credits 2,404
Posts 946
Joined 2005-09-08 13:44
20-year member
UID 42345
Status Offline
This can continue
@echo off
set keyname=Microsoft is really rubbish
set /p=%keyname%<nul>name.txt
START wmic /?
简单!简单!再简单!
Floor 13 Posted 2008-01-24 21:12 ·  中国 山西 运城 联通
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
```
@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 ]
Floor 14 Posted 2008-01-24 21:29 ·  中国 上海 松江区 电信
铂金会员
★★★★
DOS一根葱
Credits 5,493
Posts 2,315
Joined 2006-05-01 10:41
20-year member
UID 54766
Gender Male
From 上海
Status Offline
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
第一高手 第二高手

Floor 15 Posted 2008-01-24 22:36 ·  中国 江西 南昌 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
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!
Forum Jump: