|
myauto
初级用户
积分 118
发帖 5
注册 2004-9-13
状态 离线
|
『楼 主』:
(已结,改用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 ]
|
|
2004-10-8 00:00 |
|
|
Wengier
系统支持
“新DOS时代”站长
积分 27734
发帖 10521
注册 2002-10-9
状态 离线
|
『第
2 楼』:
這不是Strings的問題,而是你對使用DOS環境變量並不熟悉。出現這個結果是正常的,"echo x"不顯示x才怪呢。建議你看看DOS入門方面的教材,了解一下DOS環境變量的使用方法。
|
Wengier - 新DOS时代
欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/
E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)
|
|
2004-10-9 00:00 |
|
|
myauto
初级用户
积分 118
发帖 5
注册 2004-9-13
状态 离线
|
『第
3 楼』:
可否再点拨一下,这里到底应该用什么语句才可以正确显示结果,还有Dos环境变量的使用文档那里有???非常感谢!!
|
|
2004-10-9 00:00 |
|
|
myauto
初级用户
积分 118
发帖 5
注册 2004-9-13
状态 离线
|
『第
4 楼』:
另外,还找到一片关于strings的文章,似乎说strings不能用在win2000
---------- Edited by willsort ---------
To myauto:
引用原文时,请最好使用论坛代码[quote]和[/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:
:: Input1.cmd - A routine to prompt the user for an input string.
:: Requires WSH version 1.0 or later.
:: Input string is stored in the variable v_input
:: Use optional command line argument UCASE to convert input to all uppercase.
:: usage:
:: input1
:: input1 ucase
@ECHO off
SETLOCAL
SET v_vbs=%TEMP%\~tmp.VBS
SET v_cmd=%TEMP%\~tmp.cmd
ECHO Set oFS=CreateObject("Scripting.FileSystemObject")>%v_vbs%
ECHO oFS.OpenTextFile("CON",2).Write "Enter a string: ">>%v_vbs%
ECHO S=%1(Trim(oFS.OpenTextFile("CON",1).Readline))>>%v_vbs%
ECHO oFS.CreateTextFile("%v_cmd%",2).Write "set v_input=">>%v_vbs%
ECHO oFS.OpenTextFile("%v_cmd%",8).Write S>>%v_vbs%
cscript.exe //nologo %v_vbs%
CALL %v_cmd%
DEL %v_vbs%
DEL %v_cmd%
SET v_input
ENDLOCAL & SET v_input=%v_input% 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 ]
|
|
2004-10-9 00:00 |
|
|
Climbing
铂金会员
网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第
5 楼』:
C:\>strings x=left wang,2
C:\>echo %x%
|
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-10-10 00:00 |
|
|
StarWorld
初级用户
积分 21
发帖 7
注册 2005-9-14
状态 离线
|
『第
6 楼』:
我也遇到同样的问题了
strings x=left wang,2
echo %x%
根本就得不到wa
这是怎么回事?
|
|
2005-9-15 14:39 |
|
|
JonePeng
金牌会员
D◎$ Fαп
积分 4562
发帖 1883
注册 2004-1-19 来自 广东广州
状态 离线
|
『第
7 楼』:
Quote: | 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方式才有效。
|
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
|
|
2005-9-15 22:04 |
|
|
StarWorld
初级用户
积分 21
发帖 7
注册 2005-9-14
状态 离线
|
『第
8 楼』:
我是在windows 2000下使用的
不知道应该怎么解决这个问题??
|
|
2005-9-16 10:02 |
|
|
willsort
元老会员
Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第
9 楼』:
Re StarWorld:
在 NT 系列系统下解决你的问题,一般使用 set 命令的取子串功能;它属于命令扩展功能,故要求开启 CMD 的命令扩展,XP命令行中默认开启。如:
set x=wang
set x=%x:~0,2%
echo %x%
|
※ Batchinger 致 Bat Fans:请访问 [讨论]批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-9-16 10:24 |
|