Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to embed a tool in my script

by McDarren (Abbot)
on Feb 12, 2012 at 07:19 UTC ( [id://953290]=note: print w/replies, xml ) Need Help??


in reply to How to embed a tool in my script

If you just want to pass these files one by one to your "tool", and you don't care about any output, then you can use system

However, if your "tool" produces output that you want to capture and process, then you'll probably want to use backticks, eg:

$output_from_my_precompiled_tool = `/path/to/my/tool $file`;
Cheers,
Darren

Replies are listed 'Best First'.
Re^2: How to embed a tool in my script
by angel_perl (Novice) on Feb 12, 2012 at 13:43 UTC

    Thanks @Darren, will the code look like this? and also i want the output to be printed for respective files as different files in different directory

    my $dir = '/path/to/dir'; # read only pd files: opendir DIR, $dir or die "read dir $dir - $!"; my @pdb_files = grep /\.pdb/, readdir DIR; closedir DIR; foreach my $file (@pdb_files) { open( FH,"$dir\\$file") while(<FH>) { $output_from_my_precompiled_tool = `/path/to/my/tool $file`; } close(FH); }
      Well, no. Probably not.

      I'm not exactly clear whether you want to pass each entire file to your external tool, or whether you want to open each file and then pass it line by line. I guess probably the former. If that's the case, then perhaps this example will help.

      $ echo 'some text' > 1.pdb $ echo 'some more text' > 2.pdb
      Lets say for example your external tool is /bin/cat, and you want to cat each file and capture the output.
      $ cat foo.pl #!/usr/bin/perl use strict; use warnings; my $dir = '.'; my $cat = '/bin/cat'; opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; for my $file (@pdb_files) { my $content = `$cat "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; }
      $ perl foo.pl Content of 1.pdb is some text Content of 2.pdb is some more text
      That should be enough to get you going?

        Sorry @Darren the program doesn't seems to work because its asking for two input files first input file is the exterior script(written already)and the second input is the PDB files. So,i think incorporating a function which calls the script file first followed by the PDB files will help. So, could you please tell me how to do this?

        will the code look like this? after embedding the external script ?

        #!/usr/bin/perl use strict; use warnings; my $dir = '.'; #for embeding the mcsearch percompile version my $mcsearch = '/bin/mcsearch'; #to read the PDB files from the directory opendir DIR, $dir or die "Cannot open directory $dir:$!\n"; my @pdb_files = grep { -f $_ && $_ =~ /\.pdb$/ } readdir DIR; closedir DIR; print "Enter the script file"; $a=<>; open(IN,$a) or die; #giving each file as a input to mcsearch for my $file (@pdb_files) { while(<>) { my $content = `$mcsearch "$dir/$file"`; chomp $content; print "Content of $file is $content\n"; } }

        http://www.major.iric.ca/MajorLabEn/MC-Tools_files/MC-Annotate.zip here is the tool, i want to embed this tool and give the inputs to the tool, the web version of this tool looks like http://www.major.iric.ca/MC-Search/

        So looking at the web version i was trying to provide two inputs

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://953290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-16 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found