LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-29-2005, 06:09 PM   #1
eagle683
Member
 
Registered: May 2005
Posts: 38

Rep: Reputation: 15
Perl question


Hey all,

I am using perl to open another program and to run the program.

The program uses a shell, and I was wondering how to exactly program with it.

Right now I have:

$prog = "prog";
$status = system($$prog");

#The program opens correctly in a shell, I don't know how to run the shell of the new program
#this is what I have tried

print $status "open blablablablablabla"; #but it is the correct syntax and all

any tips?

Thanks in advance

eagle
 
Old 06-29-2005, 07:20 PM   #2
rose_bud4201
Member
 
Registered: Aug 2002
Location: St Louis, MO
Distribution: Xubuntu, RHEL, Solaris 10
Posts: 929

Rep: Reputation: 30
Are you trying just to execute the program, or to control it and give input to it while it's running? Simply executing the program is almost what you've got there:

$returnValue = `command goes here`;
For example, to grep for the phrase "stuff" in a file "textfile.txt", you'd do
$returnValue = `grep stuff textfile.txt`
just like it was on the commandline.

Using system() won't actually get you a meaningful return value, in case you're looking for one.

Giving continuous input to a program you're trying to kick off inside of your perl script is quite a bit more complicated.

Edit: for clarity's sake, those are backticks (`), not single-quotes (').
 
Old 06-30-2005, 12:10 AM   #3
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 31
IIRC Perl allows you to use pipes to interact with other programs. If you want to write to the standard input of a program, you have to create a file handler like this:

Code:
FH = open("| programname","w");
then any print FH "..." will be received by programname as input. Conversely, you can do

Code:
FH = open("programname |", "r");
and reading from FH will use the output of programname.

HTH!

PS: There has been a lot of time since the last time I programed in Perl, so the syntax could be slightly different.
 
Old 06-30-2005, 08:28 AM   #4
johnMG
Member
 
Registered: Jul 2003
Location: CT, USA
Distribution: Debian Sarge (server), Etch (work/home)
Posts: 601

Rep: Reputation: 32
If that birthday cake near your name means it's your birthday, happy birthday enemorales.
 
  


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
Perl Question rjcrews Programming 15 12-12-2005 09:34 AM
perl question nooodles Programming 5 09-22-2005 02:01 AM
Hiding code in PERL, perl gui question randomx Programming 1 06-26-2004 03:22 PM
Perl Question cbarone Linux - Software 1 12-17-2003 10:25 PM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM

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

All times are GMT -5. The time now is 11:28 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