LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-29-2006, 09:48 PM   #1
STAGED
LQ Newbie
 
Registered: Jun 2005
Location: Agoura Hills, CA
Distribution: FC3
Posts: 17

Rep: Reputation: 0
Perl question: Anyway to invoke Linux commands...


Perl question: Is there a way **in a Perl script** to invoke a Linux command (i.e., . I know there are a few Linux/UNIX commands that are inherited (more or less) in built-in Perl functions.

But is there a general way for a Perl script to use Linux commands from the script???

Thanks in advance.

P.S.: This is not homework, merely a side curiosity...Perl for Perl's sake I profess.
 
Old 01-29-2006, 11:30 PM   #2
microsoft/linux
Senior Member
 
Registered: May 2004
Location: Sebec, ME, USA
Distribution: Debian Etch, Windows XP Home, FreeBSD
Posts: 1,445
Blog Entries: 9

Rep: Reputation: 48
I know in C/C++ you do
Code:
system("<linux command goes here>");
and that will run the command. I'm not sure about Perl, but my understanding is that the 2(or 3, depending on how you look at it) languages are pretty close. This runs the command completely separately.
 
Old 01-29-2006, 11:36 PM   #3
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
backticks

@lines = `ls -al`;

shares the key with tilde ~

hth
 
Old 01-29-2006, 11:43 PM   #4
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
system() works in Perl too: http://perldoc.perl.org/functions/system.html
 
Old 01-29-2006, 11:54 PM   #5
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Perl gives you LOTS of ways to execute system commands...

Equivalently, Perl also lets you treat a Linux command as a file handle:
Code:
open (WHOPROC, "who|") or die "Unable to run 'who'!\n";
while (<WHOPROC>) {
  print "the next line of input is: " . $_;
}
close WHOPROC;
Your .. PSM
 
Old 01-30-2006, 08:43 AM   #6
STAGED
LQ Newbie
 
Registered: Jun 2005
Location: Agoura Hills, CA
Distribution: FC3
Posts: 17

Original Poster
Rep: Reputation: 0
Awesome responses. I love this forum. Thanks all.
 
Old 02-02-2006, 04:33 AM   #7
avirup dasgupta
Member
 
Registered: Aug 2003
Distribution: Redhat , Fedora Core4, DSL,Solaris
Posts: 49

Rep: Reputation: 15
also see EXEC() in perl
 
Old 02-03-2006, 11:50 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
and qx/command/

you know you can use whatever delimiter you like?

eg:
Code:
primadA$ perl
print qx|pwd|; 
/wls_domains/prima/primadA
 
Old 02-03-2006, 12:57 PM   #9
DanTaylor
Member
 
Registered: Jan 2006
Distribution: Debian Sarge
Posts: 265

Rep: Reputation: 30
Make sure that if you are going to use su only commands like kill or shutdown that you either login as su before you run or set your prgm to run as su(will need to input pass before executing rest of code);
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Invoke kickstart installation from Linux shell jeff99chapman Red Hat 2 10-26-2005 11:14 AM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM
[Perl] brainstorming with pipes & commands patator Programming 3 06-25-2004 04:17 AM
how to invoke a linux command inside a java code ? kusum Linux - Software 2 11-23-2003 01:19 PM
vim commands in perl JohanLingen Programming 5 01-08-2003 04:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:40 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration