Showing posts with label run shell script from perl script. Show all posts
Showing posts with label run shell script from perl script. Show all posts

Saturday, September 14, 2013

Run a Shell script in a Perl script

Call a Bash script in a Perl script
Run a Shell script inside Perl script
Execute Shell script in a Perl script

If you making a perl script and somewhere you want to run a bash script inside that perl script.

It can be done easily through the following piece of code.

Here is a example of an infinite loop in shell script which prints 0 infinite times.
If you run this shell script statement in terminal, it gives you 0 infinite times.
while [ 4 -le 5 ]; do  echo 0;  done;

Suppose I want to run this Shell script from a Perl script, Now I add this line of code in my perl script.

system("bash -c 'while [ 4 -le 5 ]; do  echo 0;  done;'");

Now My Perl script runs this shell script code.

Suppose this line of code is saved in a shell script file as script.sh, now if I want to run this shell script from my perl script.

I simply add this line of code in my Perl script.
system("bash -c '/root/Desktop/url.sh'");