简体   繁体   English

命令行工程-.Bat脚本不起作用

[英]Command Line Works - .Bat Script Doesn't

When attempting to run the following commands via the cmd prompt on a windows 2008 server everything works successfully. 尝试通过Windows 2008服务器上的cmd提示符运行以下命令时,一切都将成功运行。 However once those same commands are saved to a .bat or .cmd file the script no longer works. 但是,将这些相同的命令保存到.bat或.cmd文件后,该脚本将不再起作用。

@echo off
set FILE="\\servername\c$\users\users\desktop\test.txt"
FOR %I in (%FILE%) DO set SIZE=%~ZI
IF %SIZE% == 75 (
copy "\\servername\c$\users\users\desktop\test.txt" "\\servername\c$\users\users\desktop\test-1.txt"
del "\\servername\c$\users\users\desktop\test.txt"
) ELSE (
echo "Failure"
)

TIMEOUT /T -1

I'm not sure what the difference would be and would appreciate any help that can be provided. 我不确定会有什么不同,将不胜感激。 The text file I'm using has the following text in it. 我正在使用的文本文件中包含以下文本。

"
hello goodmorning 你好,早上好
I need this to have a file size. 我需要这个文件大小。

this file size is 75 该文件大小为75
"

在批处理脚本中, for循环的变量需要两个%符号。

FOR %%I in (%FILE%) DO set SIZE=%%~ZI

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从.bat脚本运行Powershell命令不起作用,但是当我直接在命令行中键入它时它可以工作 - Running Powershell command from .bat script doesn't work, however it works when I type it directly in Command Line Windows bat 脚本因多行命令而失败 - Windows bat script fails with command on multiple line 在BAT文件脚本中,如果FILE不包含该行,则在FILE中添加新行 - In BAT file script, add new line in FILE if FILE doesn't contain that line 脚本批处理不适用于.bat文件,但如果在命令提示符下编写,则可以使用 - Script batch does not work in a .bat file, but works if written in a command prompt Windows调度程序未执行批处理脚本,但是该脚本可以从命令行正常运行 - Windows scheduler isn't executing the batch script,but script works fine from command line 批量移动文件不适用于双击,但可以从命令行工作 - Move files batch doesn't work with double click but works from command line Apache PHP脚本无法连接到远程数据库/ ODBC / MySQL,但可以从命令行运行 - Apache PHP script can't connect to remote database/ODBC/MySQL but works from command line bat脚本的调用命令不起作用 - call command for bat script not working 暂停命令在.bat脚本中不起作用 - Pause command not working in .bat script 我使用7zip压缩文件夹的批处理代码在命令行中有效,但我的.bat无效 - My batch code for zipping a folder using 7zip works in command line but not my .bat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM