Re: Not able to use native linux commands in a perl script
by JavaFan (Canon) on Dec 13, 2010 at 18:03 UTC
|
Care to post the code fragment you used to copy the file? And whatever error message you're getting? Also, the relevant return variables.
Having said that, cp -rf /source /Destination looks strange to me. Do you really have a file called source in the root direction you want to copy to a file (or directory) called Destination, also in the root directory? | [reply] [d/l] [select] |
|
|
use File::Copy;
copy(source,dest);
but if you need use native linux command you must use:
`cp -rf /source /Destination`;
` - is reversive '
or
system('cp -rf /source /Destination');
But using 'system' command is dangerous in some variants...
| [reply] |
|
|
| [reply] |
|
|
|
|
|
|
please see the code fagment below
#! /usr/bin/perl
print "Hi\n";
'cp -rf /nihad /tmp/';
Here nihad is a file in my root directory and iam tying to copy this file to /tmp.
| [reply] |
|
|
I guess you failed to read my admonishment to use <code> tags... Let me make sure I have this right:
#! /usr/bin/perl
print "Hi\n";
`cp -rf /nihad /tmp/`;
You say that 'nihad' is in 'my root directory'. The use of a possessive bothers me. Some people use 'my root dir' and 'my home dir' interchangeably. Also, since most linux installations have a /root directory (the home dir for user root), that is often what people refer to as the 'root directory'. If, indeed, the file 'nihad' is in the '/' directory, the only reason I can see for it not working is permissions. Does the user you are running the script under have read-permission for both the file 'nihad' and the directory '/'? What happens when you type this command from the shell, as the same user (without the 'f' option, so it will give you an error message if it fails)?fnord | [reply] [d/l] |
|
|
Re: Not able to use native linux commands in a perl script
by toolic (Bishop) on Dec 13, 2010 at 18:13 UTC
|
| [reply] |
|
|
File::Copy
Or rather File::Copy::Recursive for cp -r functionality.
Unfortunately, it's not a core module... which might be reason enough for someone to just stick with shelling out to the system cp — unless portability is a concern.
| [reply] [d/l] [select] |
Re: Not able to use native linux commands in a perl script
by Illuminatus (Curate) on Dec 13, 2010 at 18:04 UTC
|
It will be very hard to provide advice without the actual code you are using. Perhaps you could provide the relevant portion (remember to use <code> tags)fnord | [reply] |
Re: Not able to use native linux commands in a perl script
by ww (Archbishop) on Dec 13, 2010 at 18:40 UTC
|
Special attention to the documents re File::Copy, highlighted by toolic!
There are -- occasionally -- valid reason for using shelling to system commands rather than using Perl functions (modules). What you've described is NOT one of them.
And, as others noted, we can't be much (reliable) help without knowing what your code looks like and what error message you're receiving. | [reply] |
|
|
| [reply] [d/l] [select] |