Re: Copying silently.
- From: "pmj" <post@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 14 Mar 2007 06:11:21 GMT
"Frederick Williams" <Frederick_Williams@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message
news:45F7736C.BF73D17B@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
pmj wrote:
"Frederick Williams"
<Frederick_Williams@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message
news:45F76920.B62787B3@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Ali wrote:<snip>
On Tue, 13 Mar 2007 20:51:31 GMT, Frederick Williams commented
Is there a switch to copy that means "Keep quite unless the
source doesn't exist."?
There is no switch that means "keep Quiet" at all, which is why
you redirect the output to nul:
It ought to be possible to redirect standard output and error
output independently of one another, you can with Unix.
Hang on a mo...
I *think* that it is?
Well maybe. It looks like 1> redirects standard output and
2> redirects error output. The trouble is copy seems to think
that "can't find the file" and "done it" are both standard or both
errors. I can't remember which now, see my reply to Ali.
Yep I saw that.
The "1>" & "2>" stuff (along with something like "2>&1") was
what I was thinking of.
But it does seem to be a bit "inconsistent" (or maybe just plain buggy)
There seems to be conflicting Info available about it.
I had a look here...
http://www.answers.com/topic/cmd-exe
& that mentions using "more" in the Command Line...
<quote>
(more does not wait for user input in this non-interactive context,
and is included to overcome an apparent bug that otherwise still
sends errors to the screen)
</quote>
That Article seems to be (substantially) similar, though not Identical
to this Article on Wikipedia (as many Sites do share stuff like that)
....
http://en.wikipedia.org/wiki/Windows_command_line
But the Wikipedia Article doesn't mention that last bit.
This M$KB Article explains something about it...
http://support.microsoft.com/kb/110930
& this M$KB Article is specifically about:
"How to spawn console processes with redirected standard handles"
http://support.microsoft.com/kb/190351
Which is what you are doing, isn't it?
& that Article has some examples of Program Code that use those
techniques.
Also, you can specify both "1>" & "2>" on the same Command Line,
so as to ReDirect both StdIn & StdErr for a Command, which may help you?
What about doing that & then Piping it to "find" or something
& passing the Output on to the next bit of the Command Line?
Also, apparently you can use things like "&" to put a number of
Commands onto a single Command Line & you can *also* use "&&" & "||"
to do "Conditional Command Execution...
<quote>
(from an old WinNT Command Reference I came across on the M$DN Site)
The && and || compound command symbols provide conditional command
execution. The first (left) command is executed. If the && symbol
is used, the second command executes only if the first command
completed successfully. If the || symbol is used, the second command
executes only if the first command did not complete successfully.
A command completes successfully if it returns an exit code
of 0 or no exit code at all. Exit codes are discussed in chapter 3.
For example:
C:\>verify on || echo Verify command failed!!
Since the VERIFY command executed successfully, the ECHO command was
not executed. However, in this example:
1. C:\>verify ox || echo Verify command failed!!
2. An incorrect parameter was
3. entered for the command.
4. Verify command failed!!
The ECHO command was executed because the VERIFY command syntax was
incorrect, causing the command to exit with a non-zero error code.
Multiple commands can be chained together using additional && and ||
compound command symbols. For example:
C:\>dir && copy a b && echo OK!
The COPY command executes only if the DIR command succeeds, and the
ECHO command executes only if the COPY command succeeds.
The parentheses symbols ( and ) are used to resolve command ambiguities
and indicate the binding of compound command and redirection symbols.
They are also used in the IF command and to specify multi-line commands.
For example, the following command collects two directory listings
into the file FILES.TXT:
C:\>dir *.exe >files.txt & dir *.com >>files.txt
</quote>
I'm sure some of that is pretty nearly what you are trying to do?
Especially (if I'm not completely Confuzzled now!) that 2nd to last one?
:-)
Though I'm not completely sure about what constitutes a "failure"
of the DIR Command.
Ah!
Yep - I *think* we might have sussed your original Query/Requirement?
I just tried this (using the /b Switch to give a "bare" DIR Output,
with none of the usual "Header" information)...
dir /b x.txt && copy /y x.txt z.txt && echo OK!
In a directory that had x.txt & y.txt in it...
The Output was:
<quote>
x.txt
1 file(s) copied.
OK!
</quote>
& the File "x.txt" was Copied to a File "z.txt", Creating z.txt cos
it didn't already exist.
& doing it again, Copied the File again (overwriting the first "z.txt")
Then I deleted "x.txt" & tried it & (as expected?) The output was just:
File Not Found
Maybe with some "||" as well, (& some redirection to nul) you could
string enough Conditional Commands together, to be able to do what you
want?
When I tried this...
dir /b >nul x.txt && copy /y x.txt z.txt >nul && echo OK!
I got (as I hoped/expected that I would) just this output...
<quote>
OK!
</quote>
Without the preceding Lines of:
<quote>
x.txt
1 file(s) copied.
</quote>
Though, when I deleted the File "x.txt" & tried it I got this...
<quote>
File Not Found
</quote>
Ah...
I *think* I understand it a bit better now (though I haven't yet tried
using the "||" (Negative Conditional) thingies)...
Using this next Command Line (ReDirecting the StdErr to "nul") & with
the /b (Bare) Switch for the DIR Command & the "/y" (Confirm overwrite)
Switch for the COPY Command & ReDirecting the Output of the COPY Command
to "nul"...
dir /b 2>nul x.txt && copy /y x.txt z.txt >nul && echo OK!
& with no File called "x.txt" I got no Output at all & no File was
Copied.
Then, using the same Command Line & *with* a file called "x.txt"
present,
I got the Output:
<quote>
x.txt
OK!
</quote>
& the File "x.txt" was Copied to "z.txt", just like before, but with
no line saying
<quote>
1 file(s) copied.
</quote>
So, all in all I'm pretty sure that you *can* do what you wanted to do.
Sorry about all the <quote>...</quote> stuff, but I was finding it
hard to differentiate (in this Post) between my Command Lines/
Descriptions & the Output I was getting from them on my Screen
(& that I wanted to refer to/quote in this Post)
HTH
--
pmj
.
- Follow-Ups:
- Re: Copying silently.
- From: Frederick Williams
- Re: Copying silently.
- From: Tyke
- Re: Copying silently.
- References:
- Copying silently.
- From: Frederick Williams
- Re: Copying silently.
- From: Ali
- Re: Copying silently.
- From: Frederick Williams
- Re: Copying silently.
- From: pmj
- Re: Copying silently.
- From: Frederick Williams
- Copying silently.
- Prev by Date: Re: Digital SLR Cameras - Recommendations?
- Next by Date: Re: Copying silently.
- Previous by thread: Re: Copying silently.
- Next by thread: Re: Copying silently.
- Index(es):
Relevant Pages
|