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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving Files

Status
Not open for further replies.

rottmanja

Programmer
Aug 5, 2008
17
US
I have run into a weird issue with moving files. When attempting to move a file from one directory to another. The move works somewhat.

I have these directories/files:

From: /mnt/fds-phx/docTmp/coded/1.tif
to: /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp

The issue that I am facing is, when I try to move from the from directory to the to directory. The file is moved to /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814 instead of /mnt/fds-phx/plSystem/transactions/active/98E98657-D4A3-6B6B-EF2990B199D75814/tmp

I have no idea why it is completely ignoring the /tmp part of my string.


Here is my current code.

Code:
		# read trans barcode 
		$primer = Util::Util::trim(Util::Util::fileDecode($transFile));
		
		# set transaction folder path
		my $transPath = $wDir . "plSystem/transactions/active/".$primer."/tmp";

			print "Transpath : " . $transPath . "\n"; 
			print "FileName : ".  $transFile . "\n";
			system("cp $transFile $transPath");
 
Do you happen to have a copy of the camel book?
If so, look under the function definition for 'system' - there is a recipe for examining the return value from a system call. It may possibly provide some insight.

Add one more print to your code
Code:
if(-d $transPath){
   print "Transpath : " . $transPath . "\n";
   print "FileName : ".  $transFile . "\n";
   print "Cmd      : >cp $transFile $transPath<\n";
   $rc = system("cp $transFile $transPath");
   &examine_call_results($rc) ;
}
The extra ><'s here are just an old debugging habit of my to help look for white space (or nulls when I was sure I had a valid value) I'm printing the system command inline versus using the "bla" . $var . "bla" option as it more closely matches what you're sending to system(). Just kind of curious to know if you can cut-n-paste the output and make that work as well.


If you don't have the book, I'll post a copy of it in here if I can get secondary confirmation that I'm not breaking any copyright laws. I'm sure the code is already web accessible under one of the various perl::faq sites, but they may have known something I don't.

Another possibility might be to try using the system call like
Code:
  system("cp", $transFile, $transPath);
as this is how the command is described in the book.

I do agree that this is very peculiar. I have a couple of other ideas, but they're approaching silly. Will wait until you've had another go at it.
 
Yep using the output from print "Cmd : >cp $transFile $transPath<\n"; works like as expected.

I am looked at my camel book, and I can with 100% certainty say that it is using sh.

Something very odd is going on that I have never seen.
 
OK - in lieu of any "&examine_call_results($rc)" feedback, lets start heading toward the silly:

- Try a length EXPR command on your "cp src des" and print that. Then count the characters printed with the "CMD: xxx". Verify they're the same -- perspective is from a case where I somehow gotten a backspace character in my command string. When printed to the screen, the ascii terminal window effectively used it and left me with the results. Cut-n-paste the results - all was good. Via the code - grief. (In particular I'd created a file name " <backspace>my_file" The file looked ok under an ls command but trying to use it was impossible) - I bring this up because you are generating part of your file path from another utility.

- This one I don't like but for the sake of getting your code to work so that you can move on
Code:
 system("echo 'cp src des' >/tmp/run.me");
 system("chmod 777 /tmp/run.me");
 system("/tmp/run.me");
 system("rm /tmp/run.me"); # clean up your mess
If this works - I completely agree it's ridiculous, but get the rest of your code working, then come back to this (if it works that is)
 
After a bit more testing, I think I have the issue figured out. There is one of two possibilities. Either the file that is being generated is either corrupt or I have a bad block on my file system. After running fsck on my server, I am pretty sure that it is a bad block.
 
argh..... a thousand lashes with a wet-noodle! ;)

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top