Percent Signs Stripped from Batch File Text(batch中需要两个%)
来源:互联网 发布:oracle数据库证书 编辑:程序博客网 时间:2024/05/29 13:35
http://forum.sysinternals.com/batch-file-problems-with-xp_topic13569.html
I am trying to convert a batch file script I wrote for Windows 98SE to run under XP however I've encountered a really annoying problem and not entirely sure how to fix it.
My script starts by drag and dropping a file to the shortcut (the batch file) on my desktop.
The batch file then evaluates %1 if null it runs notepad to edit itself otherwise it continues to run the rest of commands.
The code seems to fail under XP if the filename + path passed to %1 contains spaces but not under 98SE since it generates short file names with drag and drop.
To illustrate the problem I wrote a simple batch file called test.bat
@echo off
if "%1" == "" goto null
echo.
echo found this - %1
goto end
:null
echo.
echo nothing was passed
goto end
:end
Running test.bat
>test.bat
nothing was passed
>test.bat test
found this - test
>test.bat test "C:\Documents and Settings\User\Desktop\procexp.exe"
and was unexpected at this time.
"and was unexpected at this time." - and what is that supposed to mean??
Any suggestions??
Richard S.
molotovMy script starts by drag and dropping a file to the shortcut (the batch file) on my desktop.
The batch file then evaluates %1 if null it runs notepad to edit itself otherwise it continues to run the rest of commands.
The code seems to fail under XP if the filename + path passed to %1 contains spaces but not under 98SE since it generates short file names with drag and drop.
To illustrate the problem I wrote a simple batch file called test.bat
@echo off
if "%1" == "" goto null
echo.
echo found this - %1
goto end
:null
echo.
echo nothing was passed
goto end
:end
Running test.bat
>test.bat
nothing was passed
>test.bat test
found this - test
>test.bat test "C:\Documents and Settings\User\Desktop\procexp.exe"
and was unexpected at this time.
"and was unexpected at this time." - and what is that supposed to mean??
Any suggestions??
Richard S.
Members Profile
Send Private Message
Find Members Posts
Visit Members Homepage
Add to Buddy List
Moderator Group
Joined: 04 October 2006
Status: Offline
Points: 17492 Post Options
Post Reply
Quote molotov
Report Post
Quote Reply Posted: 07 February 2008 at 2:50pm
Hi Richard,
Edited by molotov - 07 February 2008 at 2:52pm
Try:
test.bat "hamster chicken goat"
You'll get "chicken was unexpected at this time".
Try changing it to:
if "%%1" == "" goto null
(add an extra '%').
Edited by molotov - 07 February 2008 at 2:52pm
Daily affirmation:
net helpmsg 4006
net helpmsg 4006
=======
http://support.microsoft.com/kb/75634
Percent Signs Stripped from Batch File Text
Retired KB Content Disclaimer
View products that this article applies to.
This article was previously published under Q75634
SUMMARYUsing a percent sign (%) in a batch file requires that two percent signs (%%) be...
Using a percent sign (%) in a batch file requires that two percent signs (%%) be specified.
For example, the command to display "5%" from a batch file would be :
For example, the command to display "5%" from a batch file would be :
ECHO 5%%
MORE INFORMATIONMS-DOS uses %1, %2, ... %9 as replaceable command line parameters. For example,...
MS-DOS uses %1, %2, ... %9 as replaceable command line parameters. For example, before executing the command ECHO %1, %1 will be replaced with the first parameter passed to the batch file. %0 is replaced with the command used to execute the batch file.
A single percent sign on a line is treated as a "nul" character in a batch file. For example:If a command contains two percent signs, MS-DOS will treat any characters between them as an environment variable to be expanded. For example, if the SET command shows that the current environment variables arethenIf there are no characters between the two percent signs, one percent sign is stripped off and the other will remain. This is why a FOR command that echos the name of each file with a .COM extension would bebut if the same command is placed in a batch file, the following is required:Reference(s):
"Microsoft MS-DOS Batch File Quick Reference," Microsoft Press.
A single percent sign on a line is treated as a "nul" character in a batch file. For example:
ECHO % is processed as ECHO ECHO a%b is processed as ECHO ab
COMSPEC=C:\COMMAND.COM PATH=C:\DOS PROMPT=$P$G B=C
ECHO %PATH% is processed as ECHO C:\DOS ECHO a%b% is processed as ECHO aC ECHO a%b b%a is processed as ECHO aa
FOR %V IN (*.COM) DO ECHO %V
FOR %%V IN (*.COM) DO ECHO %%V
"Microsoft MS-DOS Batch File Quick Reference," Microsoft Press.
APPLIES TO
- Microsoft MS-DOS 3.1
- Microsoft MS-DOS 3.2 Standard Edition
- Microsoft MS-DOS 3.21 Standard Edition
- Microsoft MS-DOS 3.3 Standard Edition
- Microsoft MS-DOS 3.3a
- Microsoft MS-DOS 4.0 Standard Edition
- Microsoft MS-DOS 4.01 Standard Edition
- Microsoft MS-DOS 5.0 Standard Edition
- Microsoft MS-DOS 5.0a
- Microsoft MS-DOS 6.0 Standard Edition
- Microsoft MS-DOS 6.2 Standard Edition
- Microsoft MS-DOS 6.21 Standard Edition
- Microsoft MS-DOS 6.22 Standard Edition
Back to the top
Keywords:
KB75634Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Back to the top
- Percent Signs Stripped from Batch File Text(batch中需要两个%)
- Replace text string using batch file
- batch
- Batch
- Batch
- Spring Batch Read from DB and Write to File
- run a PowerShell script from a batch file
- batch change file name
- Batch File Redirection
- File batch processing
- BATCH file 与Makefile 之Batch篇
- Spring Batch 从数据库提取记录存放在text中
- dos batch file in windows
- Batch file command 基础了解
- Spring Batch 操作 CSV file
- adbpush.bat (window batch file)
- batch file to mysql command
- batch downloading file in python
- 实时截屏转为opencv格式处理
- java判断字符串是否是数字
- SQL中的「规则」 constraint 与「约束」 rule 的区别。
- 程序设计语言
- Android Service学习之本地服务
- Percent Signs Stripped from Batch File Text(batch中需要两个%)
- 采用MQTT协议实现Android推送
- 物联网产品CPU核心板,助力嵌入式培训和物联网开发
- hsl to rgb
- 单元测试利器 JUnit 4
- 任务管理器没有菜单栏
- V4L2驱动视频开发要点
- MyEclipse 7.5 正式版中文插件安装
- android widget 关系图!