Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Web CMS (TeamSite)
Success/Failure distinction on executing a command
cliffhanger
I want to execute a DOS "
move
" command using perl. But I would also like to know whether the command was executed successfully. What would be the best way of doing this?
I am on
Windows
, so if I use
system()
it doesn't return me
only 0
on success, it also returns the message "X files(s) moved" and on failure it returns me the failure reason, which is also a string.
Without hardcoding these messages, is there another way of doing this?
Backtics
behave the same way as
system()
for
"move
".
Any suggestions?
Thanks
-cliff
Find more posts tagged with
Comments
Migrateduser
I believe using File::Copy is lighter than making a system call in this case and this module will return a value for you, also.
Dave
Current Environment(s):
(1) TS 6.5 on W2K3
(2) TS 6.1 SP1 on W2K3
By the way, I miss Unix terribly.
cliffhanger
I need to do a
move/rename
, so File::Copy wouldn't really help me there. I have also tried using
rename()
but that gives me permission error.
Interesting enough, it lets me do system("
move FILE_PATH_
A
FILE_PATH_
B") but wouldn't let me use
rename(FILE_PATH_
A
, FILE_PATH_
B
);
Migrateduser
What if you were to use this syntax:
system("copy /B /Y file1 file2") or ©Failed();
You don't get an explicit value, but at least you know whether the copy/rename was successful or not.
Dave
Current Environment(s):
(1) TS 6.5 on W2K3
(2) TS 6.1 SP1 on W2K3
By the way, I miss Unix terribly.
herald10
Why not use File::Copy, as Dave suggested, and then remove the old file using unlink?
HTH
-H
herald10
It seems File::Copy has a method called move(), you can use it straight away.
Migrateduser
I agree... and cliff can always do a check for the file's existence using
if (-e $file)
, but the system call is another option. I was looking at the Copy.pm code and I don't see much or any benefit in using that module over making a system call.
Dave
Current Environment(s):
(1) TS 6.5 on W2K3
(2) TS 6.1 SP1 on W2K3
By the way, I miss Unix terribly.
cliffhanger
Sure I could use copy and delete, but I was trying to do it with one command if possible.
I think the code looks ugly with executing multiple command especially when if one fails others execution needs to stop. I would end up having lots of
< if> < else>
check. I was just trying to find out if there's a decent workaorund other than "
copy/delete
" substitution for
"move
".
cliffhanger
herald,
didn't know
File::Copy
has a
move
() function, Thanks!
Sorry dave, missed your pointer.
Adam Stoller
Have you thought of using Perl's
rename()
function?
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
cliffhanger
YES. I have already mentioned it in this thread.
rename()
gives me permission denied error.
Is using
rename()
more efficient than
File::Copy::move()
??
-cliff
Migrateduser
Each of these methods involves file system calls behind the move() and rename() front-ends, so I think at this point, it's up to you as far as which you'd prefer to use. Seriously, if rename() is giving you a problem because of permission problems, I'd be interested in why that's happening.
Dave
Current Environment(s):
(1) TS 6.5 on W2K3
(2) TS 6.1 SP1 on W2K3
By the way, I miss Unix terribly.