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
paulwhelanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

thoellriCommented:
qx{cat onefile >> otherfile};

#or

`cat onefile >> otherfile`;

#or

system("cat onefile >> otherfile");

#or

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


The first three ones are unix only (unless you have a non-standard shell with cat that is)

Tobias
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jhurstCommented:
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
  }
0
thoellriCommented:
jhurst,

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

Tobias
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

jhurstCommented:
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.
0
thoellriCommented:
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
0
jhurstCommented:
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.
0
paulwhelanAuthor Commented:
i dont know who to give the points to
both answers work!
thanks guys
paul
0
paulwhelanAuthor Commented:
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.....
0
jhurstCommented:
that may be the better solution, if it works.  I was assuming that the
isp would not allow you cat-access.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.