Link to home
Start Free TrialLog in
Avatar of paulwhelan
paulwhelan

asked on

system call

i try to use syscall('');
and system('');
in a script but cant get them to work
how would i do a system call to copy the contents
of one file onto the end of another file?
thanks
paul
ASKER CERTIFIED SOLUTION
Avatar of thoellri
thoellri

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhurst
jhurst

I suspect that your web-service provider is not allowing you to execute shell commands from perl.  This is quite common.  Also, such commands are OS specific.

A much safer, and universal method is:

open(FILE1,"<filetocopyfrom");
open(FILE2,">>filetocopyto"); #the >> causes an append mode open
while (<FILE1>) #read all lines
  {print FILE2 $_; #and copy them
  }
jhurst,

can you tell me what the differnce between your solution and my last proposal is?

Tobias
The difference is that my solution does not require that cat be available, as for example it is not in DOS or on any system where the security settings are such that the cat is not available even though it exists.
Hmmm - I don't see any 'cat' appearing in this solution:

                                      open(ONEFILE,"<onefile")|| die "Can't open onefile - $!";
                                      open(OTHERFILE">>otherfile") || die "Can't open otherfile - $!";
                                      while(<ONEFILE>) {
                                        print OTHERFILE $_;
                                      }
                                      close(OTHERFILE);
                                      close(ONEFILE);

Time to clean my glasses ...
  Tobias
neither do I.  Only in the three other ones.  Actually, given that I do not see why you did not post it as an answer.

Anyway, if Paul thinks it works and awards points, and you need them.  I will be happy to post a question for thoellri that gives him this number of points.
Avatar of paulwhelan

ASKER

i dont know who to give the points to
both answers work!
thanks guys
paul
im really low on points at the moment
so sorry if i can only give some to one....
i used the system("cat onefile >> otherfile");

so i guess the points go to.....
that may be the better solution, if it works.  I was assuming that the
isp would not allow you cat-access.