How to capture system output on NT?

P

Pea

Hello,
I have a script which copies files on NT from one server to another.
I would like to do a test/confirmation of the copy. Here is my
command which reads the file name from STDIN:

system ("copy /V $_ $destination");

On NT if the file is copied successfully it will read "1 file(s)
copied." How can I get more descriptive output or read the output and
if it reads "1 file(s) copied.", print something that tells the file
name was copied to the destination. I tried $| and it printed a '1'
with a good copy and an unsuccessful copy. I also tried writing the
output to a file with >> but I have a feeling that reading that file
for errors is not the best way to do this.

I also tried adding "or die..." but that always said the file was
missing even though it was already copied.

any hints?
thanks!
 
B

Brian McCauley

system ("copy /V $_ $destination");

On NT if the file is copied successfully it will read "1 file(s)
copied." How can I get more descriptive output or read the output and
if it reads "1 file(s) copied.", print something that tells the file
name was copied to the destination. I tried $| and it printed a '1'
with a good copy and an unsuccessful copy. I also tried writing the
output to a file with >> but I have a feeling that reading that file
for errors is not the best way to do this.

Can you explain how your question is substancially different from the
FAQ: "Why can't I get the output of a command with system()?"
I also tried adding "or die..." but that always said the file was
missing even though it was already copied.

Note: system() is unual - it returns _false_ on _success_.

Note: The status of the child process is returned in a special global
variable.
any hints?

For everything I've said above and much more information about the
system() function in Perl see the section of the Perl reference manual
dealing with system().

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
M

Malcolm Dew-Jones

Pea ([email protected]) wrote:
: Hello,
: I have a script which copies files on NT from one server to another.
: I would like to do a test/confirmation of the copy. Here is my
: command which reads the file name from STDIN:

: system ("copy /V $_ $destination");

: On NT if the file is copied successfully it will read "1 file(s)
: copied." How can I get more descriptive output or read the output and
: if it reads "1 file(s) copied.", print something that tells the file
: name was copied to the destination. I tried $| and it printed a '1'
: with a good copy and an unsuccessful copy. I also tried writing the
: output to a file with >> but I have a feeling that reading that file
: for errors is not the best way to do this.

: I also tried adding "or die..." but that always said the file was
: missing even though it was already copied.

: any hints?
: thanks!

try
$results = `copy /V $_ $destination`;

and on nt I think you can also capture the error similar to sh so


$results = `copy /V $_ $destination 2>&1`;

should also get any error messages
 
P

Pea

: any hints?
: thanks!

try
$results = `copy /V $_ $destination`;

and on nt I think you can also capture the error similar to sh so


$results = `copy /V $_ $destination 2>&1`;

should also get any error messages

The first one worked. Thanks!
Tara
 
J

Jürgen Exner

Pea said:
I have a script which copies files on NT from one server to another.
I would like to do a test/confirmation of the copy. Here is my
command which reads the file name from STDIN:

system ("copy /V $_ $destination");

On NT if the file is copied successfully it will read "1 file(s)
copied." How can I get more descriptive output or read the output and
if it reads "1 file(s) copied.", print something that tells the file
name was copied to the destination. I tried $| and it printed a '1'
with a good copy and an unsuccessful copy. I also tried writing the
output to a file with >> but I have a feeling that reading that file
for errors is not the best way to do this.

Why don't you start by reading the documentation for the functions you are
using?
In this case you may want to pay particular attention to the third
paragraph:

<quote>
[...] This is
*not* what you want to use to capture the output from a command,
for that you should use [...]
</quote>

Or maybe check the FAQ. It has an entry addressing exactly your question.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top