Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to execute a built-in shell command in a Perl script. 1

Status
Not open for further replies.

bamore

Programmer
Dec 22, 2003
11
US
Hi,
I need to execute "limit descriptors 128" shell command in a perl script. Any Idea how to do so?
Thanks.
 
You mean besides using backticks ` ` or the system( ) command?

Am I missing something?
 
Thanks mikepro1 for the reply. Yeah i tried system('limit') but i think it's not working.
Here is what i did:
#!/usr/local/bin/perl
system('limit');

I'm expeting it will run the limit command but i'm not getting any out put.

when i tried
#!/usr/local/bin/perl
system('ls');

Its working fine!
 
I don't know what the limit command is. Does it take any input? I.e. when you type limit, does it wait to get some input from you before proceeding, or does it just go?

Try this:

$output = `limit`;
print "The output was:\n$output";

Those are backticks (the ones just below the Escape key), not single quotes.
Backticks will capture the output.
 
The limit command is for c-shell, I would make a little script like:

#!/bin/csh
limit

and run the script with your perl.



Blue [dragon]

If I wasn't Blue, I would just be a Dragon...
 
I tried $output = `limit`;.. still not working!
It just printing: The output was:

"limit" command sets or gets limitations on the system resources available to the current shell and its descendents

When I issue limit command from shell I get (what I’m expecting )as
cputime unlimited
filesize unlimited
datasize 2097148 kbytes
stacksize 8192 kbytes
coredumpsize 0 kbytes
descriptors 64
memorysize unlimited

 
Is the 'limit' command in the users $PATH who is running the Perl script? If not, provide the absolute path.

system('/bin/ls');

Chris
 
I did not find out where(path) is limit command. I guess this is a built-in shell command so there is no path for it; it is just a input to a shell!
Anyway Happy Holidays!
 
From a shell, type 'which limit' to find out where the executable exists. Then use the absolute path in your shell script...

system('/path/to/limit');

Chris
 
Yes, you can find out where the executable exists in the current system enviornment but i think "limit" is not a executive file!
I had tried which but system could not find the path for it.
 
A built-in shell command really not an executable; it is actually a subroutine built in to the shell program.
 
I see now, sorry, I'm not familiar with the C-shell. Try this..

system('/bin/csh');
system('limit');


Chris
 
I think you may need to make that one system call instead of 2, i.e.
Code:
$return = system(qq(/bin/csh;limit));
I don't have access to a Unix box to test, but I believe if you do it as one system call you'll be right back where you started when the process spawned by the first call terminates, so it will be just as though the first call never happened. Try it as above.
 
I was reading and came across the answer to your problem and remembered that someone asked how to execute a built-in C shell command from within a Perl script. This works, I tested it...

#!/usr/bin/perl

system("/bin/csh -c limit");


Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top