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.
我正在尝试执行命令xcopy path1 path2 / Y / C,当我从命令行尝试并且当我将其复制到批处理文件并双击该批处理文件时,它正在成功执行。
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
Working case:
C:\abcd>cmd.exe /C "xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z"
C:\abcd\itsme.bat
1 File(s) copied
Extra Info:
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
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
在这里,如果我双击Runme.bat,copy.bat正在执行并复制所有文件。 1文件已复制1文件已复制1文件已复制
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
但问题是,当我尝试从Windows调度程序运行相同的批处理文件时,它不会复制任何内容。输出:0文件已复制0文件已复制0文件已复制
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.
看起来问题只是在第二个批处理文件中使用copy命令,它将返回输出。但是其他批处理文件clean.bat(我从第一个批处理文件调用)中的所有命令都没有任何问题。第二个批处理文件有简单的echo命令,这就是为什么它工作正常。
3 个解决方案
#1
3
Use xcopy with 'START' command. For example, c:>> START xcopy "C:\folder1\itsme.bat" Y:\ /C /Y /Z
使用xcopy和'START'命令。例如,c:>> START xcopy“C:\ folder1 \ itsme.bat”Y:\ / C / Y / Z
As Mofi pointed out, you can remove 'CMD'
正如Mofi指出的,你可以删除'CMD'
#2
1
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 /?获得有关此命令的帮助。
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.
如果已经打开命令提示符窗口并输入命令,则通常不需要使用命令cmd。批处理文件由cmd解释/处理,因此在批处理文件中使用cmd通常没有意义。
So use only xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z
in already opened command prompt window and in the batch file.
因此,在已打开的命令提示符窗口和批处理文件中仅使用xcopy“C:\ folder1 \ itsme.bat”“Y:\”/ C / Y / Z.
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之类的批处理文件中处理批处理文件2之类的另一批处理文件,并在批处理文件2处理完成后继续处理批处理文件1,请在批处理文件1中使用命令调用,以便像子程序一样调用批处理文件2。
Example for batch file 1
:
批处理文件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.
Example for batch file 2
:
批处理文件2的示例:
echo This is batch 2 running XCOPY.
xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z
echo XCOPY finished, batch 2 terminates.
Run batch file 1
and you get the output:
运行批处理文件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.
Remove command call in batch file 1
, execute it again and look what you get now.
删除批处理文件1中的命令调用,再次执行它并查看您现在获得的内容。
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.
这次没有在批处理文件1中调用,批处理文件1的处理在批处理文件2上继续,而在到达批处理文件2处理结束时不返回批处理文件1。
#3
0
From your extra information it may be that x:
y:
z:
are network drives and task scheduler doesn't have network privileges under the system account.
根据您的额外信息,可能是x:y:z:是网络驱动器,任务调度程序在系统帐户下没有网络权限。
Also, change the name of copy.bat
because copy is a system command and using system command names will bite you one day, if not today.
另外,更改copy.bat的名称,因为copy是一个系统命令,如果不是今天,使用系统命令名称会有一天咬你。
#1
3
Use xcopy with 'START' command. For example, c:>> START xcopy "C:\folder1\itsme.bat" Y:\ /C /Y /Z
使用xcopy和'START'命令。例如,c:>> START xcopy“C:\ folder1 \ itsme.bat”Y:\ / C / Y / Z
As Mofi pointed out, you can remove 'CMD'
正如Mofi指出的,你可以删除'CMD'
#2
1
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 /?获得有关此命令的帮助。
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.
如果已经打开命令提示符窗口并输入命令,则通常不需要使用命令cmd。批处理文件由cmd解释/处理,因此在批处理文件中使用cmd通常没有意义。
So use only xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z
in already opened command prompt window and in the batch file.
因此,在已打开的命令提示符窗口和批处理文件中仅使用xcopy“C:\ folder1 \ itsme.bat”“Y:\”/ C / Y / Z.
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之类的批处理文件中处理批处理文件2之类的另一批处理文件,并在批处理文件2处理完成后继续处理批处理文件1,请在批处理文件1中使用命令调用,以便像子程序一样调用批处理文件2。
Example for batch file 1
:
批处理文件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.
Example for batch file 2
:
批处理文件2的示例:
echo This is batch 2 running XCOPY.
xcopy "C:\folder1\itsme.bat" "Y:\" /C /Y /Z
echo XCOPY finished, batch 2 terminates.
Run batch file 1
and you get the output:
运行批处理文件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.
Remove command call in batch file 1
, execute it again and look what you get now.
删除批处理文件1中的命令调用,再次执行它并查看您现在获得的内容。
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.
这次没有在批处理文件1中调用,批处理文件1的处理在批处理文件2上继续,而在到达批处理文件2处理结束时不返回批处理文件1。
#3
0
From your extra information it may be that x:
y:
z:
are network drives and task scheduler doesn't have network privileges under the system account.
根据您的额外信息,可能是x:y:z:是网络驱动器,任务调度程序在系统帐户下没有网络权限。
Also, change the name of copy.bat
because copy is a system command and using system command names will bite you one day, if not today.
另外,更改copy.bat的名称,因为copy是一个系统命令,如果不是今天,使用系统命令名称会有一天咬你。