Author |
Topic: Using OSCLI to call xcopy (Read 1212 times) |
|
mavison
New Member
member is offline


Posts: 14
|
 |
Using OSCLI to call xcopy
« Thread started on: Jan 25th, 2010, 9:35pm » |
|
I have a requirement to copy the entire contents of a folder (about 30 files and two sub-folders with another 10 files). It seemed the easiest way to use OSCLI to call xcopy, with source, dest and flags of /D /S /Q /I to copy everything that is not same date, with no output.
This all works well, doing just what I want, BUT when it executes there is a fleeting glimpse of a black window (I assume a command window), which is unacceptable.
I tried adding '> null:' on the end of the command, with no effect.
I could probably fix it by writing code to recurse round the source folder, check if destination file exists and is the same date, and use SYS "CopyFile" if not. But I would like to avoid this if possible, so are there any other suggestions please?
|
|
Logged
|
|
|
|
softweir
New Member
member is offline


Posts: 12
|
 |
Re: Using OSCLI to call xcopy
« Reply #1 on: Jan 25th, 2010, 11:51pm » |
|
I seem to remember that adding the "@" symbol at the beginning of the command will suppress output for that command. However, this may only apply to batch files.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Using OSCLI to call xcopy
« Reply #2 on: Jan 26th, 2010, 08:32am » |
|
Quote:This all works well, doing just what I want, BUT when it executes there is a fleeting glimpse of a black window (I assume a command window), which is unacceptable. |
|
Use SYS "ShellExecute" with the final parameter set to SW_HIDE:
Code: SW_HIDE = 0
parm$ = "c:\src\*.* c:\dst\ /q/i/y"
SYS "ShellExecute", @hwnd%, 0, "xcopy.exe", parm$, "", SW_HIDE Richard.
|
« Last Edit: Jan 26th, 2010, 08:34am by admin » |
Logged
|
|
|
|
mavison
New Member
member is offline


Posts: 14
|
 |
Re: Using OSCLI to call xcopy
« Reply #3 on: Jan 27th, 2010, 7:35pm » |
|
@softweir: Sorry, but that just generated an error in the OSCLI.
@richard: Brilliant! That seems to work a treat. Many thanks.
|
|
Logged
|
|
|
|
81RED
Guest
|
 |
Re: Using OSCLI to call xcopy
« Reply #4 on: Feb 2nd, 2010, 5:02pm » |
|
Very good tip :)
Is there any way to do something similar if using the ERRORLEVEL-friendly method as described in the wiki?
Method being something like this:
Code:SYS "GetModuleHandle", "MSVCRT.DLL" TO hdll%
SYS "GetProcAddress", hdll%, "system" TO hsys%
SYS hsys%, program$ TO exitcode%
Simon
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Using OSCLI to call xcopy
« Reply #5 on: Feb 3rd, 2010, 08:25am » |
|
Quote:Is there any way to do something similar if using the ERRORLEVEL-friendly method as described in the wiki? |
|
Adapt PROCexecuteandwait by converting it into a function and using SYS "GetExitCodeProcess" to retrieve the ERRORLEVEL value.
http://bb4w.wikispaces.com/Waiting+for+an+external+program+to+terminate
Richard.
|
|
Logged
|
|
|
|
81RED
Guest
|
 |
Re: Using OSCLI to call xcopy
« Reply #6 on: Feb 3rd, 2010, 09:49am » |
|
Thanks.
Any hints as to what "HANDLE hProcess" as described on the MSDN page for the GetExitCodeProcess function might be translated into?
Naïve as I am, I was hoping that some part of the sei{} structure used by ShellExecuteEx in the link you posted could be used?
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Using OSCLI to call xcopy
« Reply #7 on: Feb 3rd, 2010, 11:24am » |
|
Quote:Any hints as to what "HANDLE hProcess" as described on the MSDN page for the GetExitCodeProcess function might be translated into? |
|
If you look you'll see I've already added the necessary routine (FNexecuteandwait) to the Wiki article I linked to:
http://bb4w.wikispaces.com/Waiting+for+an+external+program+to+terminate
So there's nothing for you to do other than copy-and-paste this code, but I am surprised you didn't realise that the process handle is sei.hProcess% - the name of the structure member (hProcess) is quite a clue!
Quote:Naïve as I am, I was hoping that some part of the sei{} structure used by ShellExecuteEx in the link you posted could be used? |
|
Well, quite! You need only have lookup up this structure in MSDN to confirm it:
http://msdn.microsoft.com/en-us/library/bb759784.aspx
Richard.
|
|
Logged
|
|
|
|
81RED
Guest
|
 |
Re: Using OSCLI to call xcopy
« Reply #8 on: Feb 3rd, 2010, 11:41am » |
|
I asked because a
Code:SYS "GetExitCodeProcess", sei.hProcess% TO exitcode% Within the procedure you kindly provided, unceremoniously causes BB4W to crash. I suspect I'm doing something blatantly stupid, as per the usual routine :P
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Using OSCLI to call xcopy
« Reply #9 on: Feb 3rd, 2010, 1:37pm » |
|
on Feb 3rd, 2010, 11:41am, Simon Mathiassen wrote:I asked because a Code:SYS "GetExitCodeProcess", sei.hProcess% TO exitcode% Within the procedure you kindly provided, unceremoniously causes BB4W to crash. I suspect I'm doing something blatantly stupid |
|
Did you take on board my comment that I'd done the work for you? The code you need, complete with the SYS "GetExitCodeProcess" and ready for you to run with no further modification, can be found here:
http://bb4w.wikispaces.com/Waiting+for+an+external+program+to+terminate
(you need to scroll down past PROCexecuteandwait to the new FNexecuteandwait I added today).
I said that in my last message, but from the tone of your reply I'm not sure you appreciated that I'd actually written the code for you and included it in the Wiki.
As far as your above comment is concerned, it wouldn't be appropriate for me to describe your attempt as "blatantly stupid". However you shouldn't be too surprised at a crash if you use an API the way you think it ought to work rather than the way it is actually documented by Microsoft to work!
A glance at the MSDN documentation shows that GetExitCodeProcess is not defined as your code would imply:
Code:DWORD GetExitCodeProcess(HANDLE hProcess) \\ imagined by SM but instead it's defined as follows:
Code:BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode) The difference is far from just cosmetic! I expect your next question will be "why did Microsoft design the API that way" to which the answer is I've no idea. There are very many inconsistencies of that kind in the Windows API, no doubt stemming from the long period of time and the large number of different people involved.
Microsoft can't even manage to spell their APIs correctly:
http://blogs.msdn.com/oldnewthing/archive/2008/05/19/8518565.aspx
Richard.
|
« Last Edit: Feb 3rd, 2010, 1:39pm by admin » |
Logged
|
|
|
|
81RED
Guest
|
 |
Re: Using OSCLI to call xcopy
« Reply #10 on: Feb 3rd, 2010, 3:19pm » |
|
Didn't I tell you I was being stupid? 
And yes, I also totally failed to realize you had updated the wiki with the perfectly working code.
It's all good now, I'm off to strip some Mneumonics and am as usual in your debt.
|
|
Logged
|
|
|
|
|