Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Output on screen for every line of copy

Status
Not open for further replies.

kensington43

Technical User
Nov 29, 2005
50
US
I dont have access to File::Copy on my Workstation so I am doing my File Copy manually.

This works:
Code:
use strict;
my $listFile = "C:\\First.txt";
my $listFile2 = "C:\\Second.txt";
open(LIST, $listFile) || die "Cant open $listFile : $!";

while(<LIST>) 
{
  system("copy $listFile $listFile2");
}
close(LIST);

The issue is when I run this in DOS command prompt it shows output of "1 file(s} copied" for each line in my Source file (First.txt).
If I have 4 lines of text it will show this:
Code:
C:\Perl\bin>copyF.pl
        1 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.
        1 file(s) copied.

Please advise how I can eliminate this output?
 
Redirect the command's output. In the *nix world, it's /dev/null but is DOS it's just nul.
Code:
system("copy $listFile $listFile2 > nul");

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
Thanks it works.

Another issue is when I copy a 1 mb Access Database from the workstation to an Info Server it does copy over but the prompt doesnt end. It just sits there even after the copy is complete. I assume if I copy a .mdb file it is more involved and there are many parts to copy. But the database opens up fine on the InfoServer even though the Perl Command still hasnt ended in my DOS prompt.

I was going to run this during midnight hour when no one is around.
 
maybe you can just use backtiks and avoid any printing back to the screen:

Code:
while(<LIST>)
{
  `copy $listFile $listFile2`;
}
close(LIST);
 
Backticks in void context is as frowned upon as grep or map in void context. Don't make perl do all the work of capturing the output when you can just tell the shell to ignore it.

As far as the DOS copy command goes, one file is no more "complicated" than another. Bigger, maybe, but it's all just data. The question is more of how does the copy script get started? That affects how it ends.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
It might just me, but doesn't this code simply copy C:\First.txt to C:\Second.txt for every line in LIST? Or is that what you want to do? Because, I can't see the use in copying the same file multiple times.
 
I realize using backtiks in void context is frowned upon, but thats not to say there are occasions when it's fine to use it that way. The output in this case is next to nothing and I can't see a problem with it, but it is still a valid concern about using these types of functions, that should return something, in void context. You wouldn't want to do it as a practice.
 
Yeah, sorry, I tend to be an extremist about such things in my head. If I don't remember to do them for the little things that don't matter, the odds I'll remember for the big things that do go down. :-/

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top