Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Interacting while in system

by Fingo (Monk)
on Mar 26, 2001 at 06:02 UTC ( #67099=perlquestion: print w/replies, xml ) Need Help??

Fingo has asked for the wisdom of the Perl Monks concerning the following question:

This has to do with my music program.

My program is supposed to call system() in an endless loop. I want the user to be able to talk to the program (skip track, quit etc...), but if I run the program with &, my script assumes the program has quit and runs it again. How do let the user talk to my script while it is system?

Thanks

Replies are listed 'Best First'.
Re: Interacting while in system
by Yohimbe (Pilgrim) on Mar 26, 2001 at 09:15 UTC
    instead of calling system() use open (FOO, "|$program) to run the program as a subprocess. Anything you print to FOO will be sent the the stdin of $program. $program, if say a perl program can do while (<STDIN>) { &process_command($_);}
    --
    Jay "Yohimbe" Thorne, alpha geek for UserFriendly
Re: Interacting while in system
by chromatic (Archbishop) on Mar 26, 2001 at 09:17 UTC
    Yohimbe has the truth of it. Look to perldoc perlipc on your system for more information. (Since you're using a shell that supports backgrounding, you probably have enough Unix that opening a pipe to the program will work. Lucky!)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://67099]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-10-27 06:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (256 votes). Check out past polls.

    Notices?