Xulong Posted February 20, 2017 Share Posted February 20, 2017 (edited) I have a script which is copying one file (the latest file among a bunch of structured folders) from one network device to another network device. The weird thing is the file copied successfully to the destination folder right after the FileCopy command ran but the script is hanging for another few minutes until it return with exit code 0. Below is my script: #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <FileConstants.au3> copyfile() Func copyfile() Local $testLogFile = FileOpen(@ScriptDir & "\CopyMSI", 1) Local $BuildArtifacts = "\\vm-build\BuildArtifacts" Local $dServer = "\\VM-DEV\c$\Users\Administrator\Desktop" Send("#r") WinWaitActive("Run") ControlSend("Run", "", 1001, $BuildArtifacts) ControlClick("Run", "OK", 1) _FileWriteLog($testLogFile, "Opened Builds folder") ;trying to get the latest build folder and grab the latest msi file for copying WinWaitActive("BuildArtifacts") Local $FolderList = _FileListToArray($BuildArtifacts, "Grand-4.*") _ArraySort($FolderList, 1) Local $latestSEbuild = $FolderList[0] Sleep (5000) WinClose("BuildArtifacts") Local $sServer = $BuildArtifacts & '\' & $latestSEbuild & '\G4.msi' ; start copying file from build to destination folder FileCopy($sServer, $dServer, $FC_OVERWRITE) _FileWriteLog($testLogFile, "Copied MSI") EndFunc Edited February 20, 2017 by Xulong Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 20, 2017 Moderators Share Posted February 20, 2017 How large is the MSI? And how long does it take you to copy that file manually? Is it a slow link? FileCopy is going to stop the script until it finishes, so if it is a large file it may take a few seconds. Longer if it is a slow link. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Xulong Posted February 20, 2017 Author Share Posted February 20, 2017 1 minute ago, JLogan3o13 said: How large is the MSI? And how long does it take you to copy that file manually? Is it a slow link? FileCopy is going to stop the script until it finishes, so if it is a large file it may take a few seconds. Longer if it is a slow link. The file is not large only under 100MB, I can see the file being successfully copied over using the script but just the script won't return exit code after successfully copied over and hanging there for a few minutes before it returns the exit code. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 20, 2017 Moderators Share Posted February 20, 2017 Is it hanging before or after the _filewritelog? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Xulong Posted February 20, 2017 Author Share Posted February 20, 2017 4 hours ago, JLogan3o13 said: Is it hanging before or after the _filewritelog? It is hanging before the _filewritelog. Link to comment Share on other sites More sharing options...
Subz Posted February 20, 2017 Share Posted February 20, 2017 Can you try something like this (untested), uses the default Windows copy process with overwrite, Jos wrote the _FileCopy function: #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <FileConstants.au3> CopyFile() Func copyfile() Local $sLogFile = FileOpen(@ScriptDir & "\CopyMSI.log", 1) Local $BuildArtifacts = "\\vm-build\BuildArtifacts" Local $dServer = "\\VM-DEV\c$\Users\Administrator\Desktop" _FileWriteLog($sLogFile, "Opened Builds folder") Local $FolderList = _FileListToArrayRec($BuildArtifacts, "Grand-4.*", 2, 0, 1, 2) Local $sServer = $FolderList[0] & '\G4.msi' _FileCopy($sServer, $dServer) _FileWriteLog($sLogFile, "Copied MSI") EndFunc Func _FileCopy($sSource, $sTarget) Local $FOF_RESPOND_YES = 16 $hWinShell = ObjCreate("Shell.Application") $hWinShell.namespace($sTarget).CopyHere($sSource, $FOF_RESPOND_YES) EndFunc Link to comment Share on other sites More sharing options...
Xulong Posted February 21, 2017 Author Share Posted February 21, 2017 @Subz Thanks for the script. It seems not copying file. Link to comment Share on other sites More sharing options...
Subz Posted February 21, 2017 Share Posted February 21, 2017 Can you try and add ConsoleWrite above _FIleCopy with ConsoleWrite($sServer, $dServer) and make sure the paths are correct? Link to comment Share on other sites More sharing options...
Xulong Posted February 21, 2017 Author Share Posted February 21, 2017 1 hour ago, Subz said: Can you try and add ConsoleWrite above _FIleCopy with ConsoleWrite($sServer, $dServer) and make sure the paths are correct? I used MSGBOX which gives me the correct path but when I use the above ConsoleWrite it gives me error incorrect parameters. So I tried my script again and it now returns the exit code straight after the FileCopy. But it hangs again when I use the script with CruiseControl as an executable task. Link to comment Share on other sites More sharing options...
Subz Posted February 21, 2017 Share Posted February 21, 2017 Can you run the code below, can you send through screenshot of _ArrayDisplay and also the output from ConsoleWrite #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <FileConstants.au3> CopyFile() Func copyfile() Local $sLogFile = FileOpen(@ScriptDir & "\CopyMSI.log", 1) Local $BuildArtifacts = "\\vm-build\BuildArtifacts" Local $dServer = "\\VM-DEV\c$\Users\Administrator\Desktop" _FileWriteLog($sLogFile, "Opened Builds folder") Local $FolderList = _FileListToArrayRec($BuildArtifacts, "Grand-4.*", 2, 0, 1, 2) _ArrayDisplay($FolderList) Local $sServer = $FolderList[0] & '\G4.msi' ConsoleWrite('Source: ' & $sServer @CRLF & 'Destination: ' & $dServer & @CRLF) _FileCopy($sServer, $dServer) _FileWriteLog($sLogFile, "Copied MSI") EndFunc Func _FileCopy($sSource, $sTarget) Local $FOF_RESPOND_YES = 16 $hWinShell = ObjCreate("Shell.Application") $hWinShell.namespace($sTarget).CopyHere($sSource, $FOF_RESPOND_YES) EndFunc Link to comment Share on other sites More sharing options...
Xulong Posted February 21, 2017 Author Share Posted February 21, 2017 @Subz after executing the above script, I got below message back: Quote >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\xulong\Desktop\CopySEMsi.au3" C:\Users\xulong\Desktop\CopySEMsi.au3 (19) : ==> Badly formated variable or macro.: ConsoleWrite('Source: ' & $sServer @CRLF & 'Destination: ' & $dServer & @CRLF) ConsoleWrite('Source: ' & $sServer ^ ERROR >Exit code: 1 Time: 0.3618 Link to comment Share on other sites More sharing options...
Subz Posted February 21, 2017 Share Posted February 21, 2017 Sorry forgot to put & in between $sServer & @CRLF can you try again after you have added it. Link to comment Share on other sites More sharing options...
Xulong Posted February 21, 2017 Author Share Posted February 21, 2017 Here is the Array (I trimed a bit as the full list is too long) Quote Row|Col 0 [0]|77 [1]|\\vm-build\BuildArtifacts\Grand-4.3.2.1327 (Sprint) [2]|\\vm-build\BuildArtifacts\Grand-4.3.2.1328 (Sprint) [3]|\\vm-build\BuildArtifacts\Grand-4.3.2.1332 (Sprint) [4]|\\vm-build\BuildArtifacts\Grand-4.3.2.1341 (Sprint) ........ ........ ........ [74]|\\vm-build\BuildArtifacts\Grand-4.3.2.1642 (Sprint) [75]|\\vm-build\BuildArtifacts\Grand-4.3.2.1645 (Sprint) [76]|\\vm-build\BuildArtifacts\Grand-4.3.2.1646 (Sprint) [77]|\\vm-build\BuildArtifacts\Grand-4.3.2.1651 (Sprint) From ConsoleWrite, the results is: Quote Source: 77\G4.msi Destination: \\VM-DEV\c$\Users\Administrator\Desktop But the file didn't be copied over to Destination. Link to comment Share on other sites More sharing options...
Xulong Posted February 21, 2017 Author Share Posted February 21, 2017 (edited) So the problem I have at the moment is the script I have post initially is working now (script not hanging after FileCopy) but when integrated with CCNet, the script is running for a few minutes and did not copy the file over (only takes 9 seconds if execute manually) Edited February 21, 2017 by Xulong Link to comment Share on other sites More sharing options...
Subz Posted February 21, 2017 Share Posted February 21, 2017 So $sServer was incorrect so have now updated it, I only used the other _FileCopy function so you could see if it was hanging during the copy. Here is your original code without the unnecessary code, like WinWait etc.. #include <MsgBoxConstants.au3> #include <File.au3> #include <Array.au3> #include <FileConstants.au3> CopyFile() Func copyfile() Local $sLogFile = FileOpen(@ScriptDir & "\CopyMSI.log", 1) Local $BuildArtifacts = "\\vm-build\BuildArtifacts" Local $dServer = "\\VM-DEV\c$\Users\Administrator\Desktop" _FileWriteLog($sLogFile, "Opened Builds folder") Local $FolderList = _FileListToArrayRec($BuildArtifacts, "Grand-4.*", 2, 0, 1, 2) _ArrayDisplay($FolderList) Local $sServer = $FolderList[$FolderList[0]] & '\G4.msi' ConsoleWrite('Source: ' & $sServer & @CRLF & 'Destination: ' & $dServer & @CRLF) FileCopy($sServer, $dServer, $FC_OVERWRITE) _FileWriteLog($sLogFile, "Copied MSI") EndFunc Xulong 1 Link to comment Share on other sites More sharing options...
Xulong Posted February 21, 2017 Author Share Posted February 21, 2017 (edited) Thank you for the script. Now I know the _FileListToArrayRec which is way more tidy and nice to use in this case. I am going to see how to fix the CC.Net issue now. Edited February 21, 2017 by Xulong Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now