Re: Copying silently.



"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:
On Tue, 13 Mar 2007 20:51:31 GMT, Frederick Williams commented
<snip>
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


.



Relevant Pages

  • Re: Calling webpage with logon script, logon script wont close
    ... what do the two "" do to the command? ... In NT and higher the first quotes are used as a title for the window ... When the batch-script quoted executes the line you suggested: ... UP TO the final quote on the line, with parameterof the remainder of the ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: Redirecting lpt1 output to an installed printer
    ... to the lpt1 port. ... I am doing now is to redirect the output using the "net use" ... If there's a recognized printer on that port, ... which I do via a "net use LPT1" command inside a batch file. ...
    (microsoft.public.vb.general.discussion)
  • Re: How to capture "legacy" program output in MSH and redirect them to MshHostUserInterface
    ... command is redirected in the script or not. ... to see if the output of the script command is the default output pipe. ... The workaround is to always explicitly redirect native ... RedirectAlways flag on the runspace that will cause legacy applications to ...
    (microsoft.public.windows.server.scripting)
  • Re: net use script issue with terminal server and DFS
    ... redirect stdout into NUL ... command will be redirected to NUL, ... But it should give you an error message when you execute the same ...
    (microsoft.public.windows.terminal_services)
  • Re: Dos quit printing yesterday
    ... redirect via the net use command without sucess. ... >With the spooler job window open, ... when attermpting to print from a "command prompt" window. ...
    (microsoft.public.windowsxp.print_fax)