从命令窗口,通过双击bat文件执行不同当Windows .bat文件的行为 [英] Windows .Bat file behave differently when executed from command window and by double clicking on the bat file

查看:755
本文介绍了从命令窗口,通过双击bat文件执行不同当Windows .bat文件的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从命令窗口,并通过双击bat文件执行时的Windows .bat文件的行为不同。这是我的文件:

Windows .Bat file behave differently when executed from command window and by double clicking on the bat file. This is my file:

ECHO ON
del activity_ftp.log
cd D:\My_Test
IF EXIST united_ops*.csv (
for %%i in (united_ops*.csv) do (
set size=0
set /A size=%%~zi
echo %%i,%size%,397312,624640 > D:\My_Test\activity_ftp.log
)
)

当我打开命令窗口,调用它运行它,

When I run this by opening command window and calling it,

推荐答案

有在code的一些问题。结果
CD D:\\ My_test 如果您是在只会工作,D:,你可以使用 CD / D PUSHD 在这里。

There are some issues in your code.
cd d:\My_test will only work if you are on D:, you could use cd /d or pushd here.

...回声%的大小%不起作用,因为它的时候,当它执行的块不会被解析扩展。

echo ...%size% doesn't work, as it's expands when the for block is parsed not when it's executed.

(如果存在)似乎是多余的,因为为%%我在(united_ops * .csv的)如果任何文件存在不仅扩展。

The if exist seems to be redundant, as the for %%i in ( united_ops*.csv) only expands if any file exists.

ECHO ON
setlocal EnableDelayedExpansion
del activity_ftp.log
pushd D:\My_Test
for %%i in (united_ops*.csv) do (
    set size=0
    set /A size=%%~zi         
    echo %%i,!size!,397312,624640 > D:\My_Test\activity_ftp.log
)

这篇关于从命令窗口,通过双击bat文件执行不同当Windows .bat文件的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆