LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Perl question (https://www.linuxquestions.org/questions/programming-9/perl-question-338532/)

eagle683 06-29-2005 06:09 PM

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

rose_bud4201 06-29-2005 07:20 PM

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 (').

enemorales 06-30-2005 12:10 AM

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.

johnMG 06-30-2005 08:28 AM

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


All times are GMT -5. The time now is 06:11 PM.