CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
System call on a file with switches

 



sparsh
Novice

Aug 21, 2015, 11:59 AM

Post #1 of 5 (1118 views)
System call on a file with switches Can't Post

hi,

I need to call a readymade perl script to help extract some data, but i need to do it through a system call, and the script itself uses some switches to run. Also, I need to append the output of this perl script to a text file, as I need that file to parse data later.

Any idea how to do this?

Some example code will be appreciated.

Sparsh


FishMonger
Veteran / Moderator

Aug 21, 2015, 12:33 PM

Post #2 of 5 (1116 views)
Re: [sparsh] System call on a file with switches [In reply to] Can't Post

What part of using the system function or output redirection do you not understand?

What have you tried?

What errors/warnings did you receive?

How did the results differ from what you expected/wanted?


sparsh
Novice

Aug 21, 2015, 12:49 PM

Post #3 of 5 (1114 views)
Re: [FishMonger] System call on a file with switches [In reply to] Can't Post

ok, so bascially this script extracts data and produces the results in a terminal. and it uses a few switches to do so. the way i usually do system calls is this:


my $commandCheck = join (" ", '/home/perl.pl', $argument1, $argument2);
system ($commandCheck)

Where perl.pl takes in 2 arguments. But doesn't require any switches to function.

Now I need to do a system call on another script, who to function, uses one switch and a file input. (i.e -r , textfile.txt).

So what I'm bascially asking is, how will this system command above be modified to accommodate the switch? And once that is done, how can I append the results of this script to a file?

I haven't tried anything yet because I don't even know if switches can be appended to system calls!

Hope this makes things abit clearer?


FishMonger
Veteran / Moderator

Aug 21, 2015, 1:02 PM

Post #4 of 5 (1112 views)
Re: [sparsh] System call on a file with switches [In reply to] Can't Post

If you want to use the same approach as you're already doing, then simply put the switch within the join statement and put the output redirection at the end.


Code
my $commandCheck = join (" ", '/home/perl.pl', '-r', 'textfile.txt', '> output.txt'); 
system ($commandCheck);


It might be best to use the list form of system.

Code
my @commandCheck = ('/home/perl.pl', '-r', 'textfile.txt', '> output.txt'); 
system (@commandCheck);



sparsh
Novice

Aug 21, 2015, 1:17 PM

Post #5 of 5 (1108 views)
Re: [FishMonger] System call on a file with switches [In reply to] Can't Post

Thanks FishMonger, Got it working.

Much appreciated.

Sparsh

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives