• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

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
0
paulwhelan
Asked:
paulwhelan
  • 4
  • 3
  • 2
1 Solution
 
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
 
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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
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

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now