Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
193 views
in Technique[技术] by (71.8m points)

windows - 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

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:folder1itsme.bat" "Y:" /C /Y /Z" 
0 File(s) copied

Working case:

C:abcd>cmd.exe /C "xcopy "C:folder1itsme.bat" "Y:" /C /Y /Z"
C:abcditsme.bat  
1 File(s) copied

Extra Info:

Runme.bat:

call C:folder1copy.bat
call C:folder1clean.bat

copy.bat:

@echo off
xcopy "C:folder1
unrun.bat" "Z:" /C /Y /Z /Q
xcopy "C:folder1
unrun.bat" "Y:" /C /Y /Z /Q
xcopy "C:folder1
unrun.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

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use xcopy with 'START' command. For example, c:>> START xcopy "C:folder1itsme.bat" Y: /C /Y /Z

As Mofi pointed out, you can remove 'CMD'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...