in reply to Not able to use native linux commands in a perl script

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?

Replies are listed 'Best First'.
Re^2: Not able to use native linux commands in a perl script
by Khariton (Sexton) on Dec 13, 2010 at 20:55 UTC
    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...
      The dangers are much overrated. They aren't specific to system, `` suffers from that as well (and system has a safer variant). However, if you accept input from untrusted sources, File::Copy is "dangerous" as well.

      But if you're in control of creating the command, neither option is more dangerous than you typing it on the command line.

        Copy is a copy...
        I mean in File::Copy input parameters has verifying for entered data.
        But if I use command system('cp '.$src.' '.$dst) and $dst can be changed by user, we have a big problem with executing any native linux commands.
        I'm not test this example, but this or like this must work.
        As example $dst='text.txt; cat /etc/passwd | mail ...'. If this script will be using with root privilege...
Re^2: Not able to use native linux commands in a perl script
by Nihad Nizar (Initiate) on Dec 14, 2010 at 03:28 UTC
    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.
      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

        I realize that the errors are result of a syntax error. Thanks every one for all your valuable suggestions.