在从另一个批处理文件调用批处理文件时,批处理文件中的复制命令未执行,但是当我双击时会执行 [英] copy command in batch file is not getting executed when calling the batch file from another batch file, but is getting executed when i double click

查看:246
本文介绍了在从另一个批处理文件调用批处理文件时,批处理文件中的复制命令未执行,但是当我双击时会执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图执行一个命令xcopy path1 path2 / Y / C,它正在成功执行,当我尝试从命令行,当我将它复制到一个批处理文件,并双击该批处理文件。

i am trying to execute a command xcopy path1 path2 /Y /C and it is getting executed successfully when i tried from command line and also when i copied it to a batch file and double clicking on that batch file.

但是当我批准另一个批处理文件失败时,它不会被执行。

But it is not getting executed when i cal this batch file from another fail.

任何人都可以在这里帮忙吗?

Could anyone please help here?

不工作的情况: >

Not working case:

C:\abcd>cmd.exe /C "xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z" 
0 File(s) copied

工作案例:

C:\abcd>cmd.exe /C "xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z"
C:\abcd\itsme.bat  
1 File(s) copied

额外信息:

Runme.bat: strong>

Runme.bat:

call C:\folder1\copy.bat
call C:\folder1\clean.bat

copy.bat:

@echo off
xcopy "C:\folder1\runrun.bat" "Z:\" /C /Y /Z /Q
xcopy "C:\folder1\runrun.bat" "Y:\" /C /Y /Z /Q
xcopy "C:\folder1\runrun.bat" "X:\" /C /Y /Z /Q

这里,如果我双击Runme。 bat,copy.bat正在执行并复制所有文件。
1复制的文件
1复制的文件
1复制的文件

Here, If I double click on Runme.bat, copy.bat is getting executed and copying all the files. 1 File(s) copied 1 File(s) copied 1 File(s) copied

但问题是,它没有复制任何东西,当我尝试从Windows调度程序运行相同的批处理文件。
输出:
0复制的文件
0复制的文件
0复制的文件

But issue is, it is not copying anything when i try to run the same batch file from windows scheduler. Output: 0 File(s) copied 0 File(s) copied 0 File(s) copied

看起来像问题只有在第二个批处理文件中的copy命令,它将返回输出。但是在其他批处理文件clean.bat(我从第一个批处理文件调用)中的所有命令正在执行没有任何问题。
第二个批处理文件有简单的echo命令,所以这是为什么它工作正常。

looks like issue is only with copy command in the second batch file, which will return output. But all the commands in the other batch file clean.bat (which i am calling from the first batch file) are getting executed without any issues. second batch file has simple echo commands, so that is why it is working fine.

推荐答案

命令 cmd 用于运行命令行解释器的新实例,并且通常只用于打开命令提示符窗口。在命令提示符窗口 cmd /?中执行以获取有关此命令的帮助。

The command cmd is for running a new instance of the command line interpreter and need to be used usually only for opening a command prompt window. Execute in a command prompt window cmd /? to get help about this command.

命令 cmd 通常不需要使用,如果命令提示符窗口已经打开并且输入了命令。批处理文件由 cmd 解释/处理,因此在批处理文件中使用 cmd 通常没有意义。

The command cmd does not need to be used usually if a command prompt window is opened already and a command is entered. A batch file is interpreted/processed by cmd and therefore it usually does not make sense to use cmd in a batch file.

因此,在已打开的命令提示符中只使用 xcopyC:\folder1\itsme.batY:\/ C / Y / Z 窗口和批处理文件中。

So use only xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z in already opened command prompt window and in the batch file.

要处理批处理文件中的另一个批处理文件,例如批处理文件2 批处理文件1 后继续处理批处理文件1 code>完成后,在调用 中使用批处理文件1 批处理文件2

To process another batch file like batch file 2 from within a batch file like batch file 1 and continue processing of batch file 1 after processing of batch file 2 finished, use in batch file 1 the command call for calling batch file 2 like a subroutine.

批处理文件1示例 p>

Example for batch file 1:

@echo off
echo This is batch 1 calling now batch 2 and is waiting until it finished.
call "batch file 2.bat"
echo Batch 1 continues.

批处理文件2示例



Example for batch file 2:

echo This is batch 2 running XCOPY.
xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z
echo XCOPY finished, batch 2 terminates.

运行批处理文件1 输出:

This is batch 1 calling now batch 2 and is waiting until it finished.
This is batch 2 running XCOPY.
XCOPY finished, batch 2 terminates.
Batch 1 continues.

批处理文件中删除命令调用 1 ,再次执行并查看您现在得到的结果。

Remove command call in batch file 1, execute it again and look what you get now.

此时 处理批处理文件1 继续 c / c>处理

This time without call in batch file 1 the processing of batch file 1 continues on batch file 2 without coming back to batch file 1 on reaching end of batch file 2 processing.

这篇关于在从另一个批处理文件调用批处理文件时,批处理文件中的复制命令未执行,但是当我双击时会执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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