中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --
联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
游客 | 登录 | 注册 | 会员 | 搜索 | 中国DOS联盟
中国DOS联盟论坛
现在时间是 2026-09-23 15:13
47,812 主题排行 / 349,917 发帖 / 今日 0 篇 / 48,273 会员排行
DOS批处理 & 脚本技术(批处理室) » (已结,改用set)Strings无法在NT环境下设置环境变量
可打印版本  1,949 / 8
第1楼 myauto 发表于 2004-10-08 00:00
初级用户 发帖 5 积分 118
(已结,改用set)Strings无法在NT环境下设置环境变量
如果输入strings left wang,2回车会得到结果wa
现在我想将wa赋到变量x上,使用如下语句
strings x=left wang,2
echo %x
但是奇怪的是得到的结果是
C:\>strings x=left wang,2
C:\>echo x
x
请问为什么这里显示的x不是wa?
多谢

---------- Edited by willsort ----------
修改原标题:用过Strings的高手请进
---------- Edited by willsort ----------


[ Last edited by willsort on 2005-9-22 at 19:00 ]
第2楼 Wengier 发表于 2004-10-09 00:00
系统支持 发帖 10,521 积分 27,736
這不是Strings的問題,而是你對使用DOS環境變量並不熟悉。出現這個結果是正常的,"echo x"不顯示x才怪呢。建議你看看DOS入門方面的教材,了解一下DOS環境變量的使用方法。
第3楼 myauto 发表于 2004-10-09 00:00
初级用户 发帖 5 积分 118
可否再点拨一下,这里到底应该用什么语句才可以正确显示结果,还有Dos环境变量的使用文档那里有???非常感谢!!
第4楼 myauto 发表于 2004-10-09 00:00
初级用户 发帖 5 积分 118
另外,还找到一片关于strings的文章,似乎说strings不能用在win2000

---------- Edited by willsort ---------
To myauto:
  引用原文时,请最好使用论坛代码[quote]和[/quote];如果是网络资料,请最好给出原文链接。
  谢谢合作!


Making it work under Windows NT and Windows 2000STRINGS and ASET (and most other environment manipulation utilities) do not work under Windows NT and Windows 2000, even though they work as advertised in a DOS session or a DOS window under Microsoft Windows 9x. Why is this, and can it be corrected?Last question first: No, the problem cannot be corrected. Though Windows 2000 may complain "not enough environment space" when running STRINGS or ASET, the problem is not due to insufficient environment space. The problem is caused by the fact that STRINGS and ASET both use the DOS interrupt call INT 21 to alter environment variables. Windows NT and Windows 2000 are incompatible with this common technique. Here are some alternate solutions:Windows 2000: Get input from keyboardTo prompt the user for a value and then put their keyboard reply into an environment variable, run this command:
SET /P VARNAME=Please enter your name:

SET will display the prompt "Please enter your name:" to the user, who is expected to type a string of lettes and press ENTER. Whatever they type will be stored in the variable %VARNAME, where it can be retrieved for later operations.Windows NT: Get input from keyboardThis technique doesn't work with Windows NT. However, Simon Sheppard (www.ss64.com) wrote this script using Windows Scripting Host (present on NT and Win2K machines) to store user input into an environment variable:


One workaround is to place the command(s) to these utilities in the file called C:\WINNT\AUTOEXEC.NT or C:\%WINDIR%\AUTOEXEC.NT. The file AUTOEXEC.NT is a "batch" file and it runs like AUTOEXEC.BAT does in normal MS-DOS. If you are able, execute ASET or STRINGS from within AUTOEXEC.NT. Every time CMD.EXE or COMMAND.COM is executed, AUTOEXEC.NT will be executed, and any variables which are set there will persist for the life of the CMD or COMMAND window.There's probably another workaround, but I don't know what it is right now. If someone else does, please e-mail me. Thanks!

---------- Edited by willsort ----------


[ Last edited by willsort on 2005-9-16 at 10:20 ]
第5楼 Climbing 发表于 2004-10-10 00:00
铂金会员 发帖 2,753 积分 6,962 来自 河北保定
C:\>strings x=left wang,2
C:\>echo %x%
第6楼 StarWorld 发表于 2005-09-15 14:39
初级用户 发帖 7 积分 21
我也遇到同样的问题了
strings x=left wang,2
echo %x%
根本就得不到wa
这是怎么回事?
第7楼 JonePeng 发表于 2005-09-15 22:04
金牌会员 发帖 1,883 积分 4,562 来自 广东广州
Originally posted by StarWorld at 2005-9-15 14:39:
strings x=left wang,2
echo %x%
根本就得不到wa
这是怎么回事?


你一定是在NT系统下用这些命令。NT下的CMD不支持通过strings命令来创建并给一个环境变量。只有在纯DOS或Win9x的MSDOS方式才有效。
第8楼 StarWorld 发表于 2005-09-16 10:02
初级用户 发帖 7 积分 21
我是在windows 2000下使用的
不知道应该怎么解决这个问题??
第9楼 willsort 发表于 2005-09-16 10:24
元老会员 发帖 1,512 积分 4,432
Re StarWorld:

在 NT 系列系统下解决你的问题,一般使用 set 命令的取子串功能;它属于命令扩展功能,故要求开启 CMD 的命令扩展,XP命令行中默认开启。如:

[ 联系联盟系统管理团队 - 中国DOS联盟 - 标准版 ]
Sponsored by ifanr Inc | © 2001–2023