CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
files copied or moved in perl script end up as zero bytes

 



regex2012
User

Nov 28, 2016, 12:30 PM

Post #1 of 3 (1618 views)
files copied or moved in perl script end up as zero bytes Can't Post

I have tried at least 6 times to use the following command to copy /move files:
(tried system with mv)
(tried file::copy and move)

What happens is that unless I am in the /tmp directory I can't move this file. The file does move, but it has zero bytes. This also happens when I use the cp command. Has anyone ever seen this?

Code
my $date=`date +%Y%m%d`; 
my $dir = "/local/mnt/logs";
chomp($date);
my $source_file="/local/mnt/inventorylog";
my $destination_file="/local/mnt/inventorylog" . $date . ".txt";
print "$source_file\n";
print "$destination_file\n";
system("cp /local/mnt/inventorylog/$dir/inventorylog_$date.txt");



(This post was edited by regex2012 on Nov 28, 2016, 2:30 PM)


BillKSmith
Veteran

Nov 28, 2016, 1:28 PM

Post #2 of 3 (1613 views)
Re: [regex2012] files copied or moved in perl script end up as zero bytes [In reply to] Can't Post

The destination of your cp command is not the file specified by $destination_file. You may be looking at an old zero-length file. Did you check its time stamp?

You say that you tried the module File::Copy. That is a much better approach. Did you check for errors like the example in its documentation?
Good Luck,
Bill


Laurent_R
Veteran / Moderator

Nov 29, 2016, 12:24 PM

Post #3 of 3 (1591 views)
Re: [regex2012] files copied or moved in perl script end up as zero bytes [In reply to] Can't Post


Code
system("cp /local/mnt/inventorylog/$dir/inventorylog_$date.txt");

At the very least, there is a space missing in your system command:


Code
system("cp /local/mnt/inventorylog $dir/inventorylog_$date.txt");


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives