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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
12-03-2004, 03:38 PM
|
#1
|
LQ Newbie
Registered: Aug 2003
Posts: 6
Rep:
|
Perl program control
I'm wondering if there is a way to have perl step through menu options after running a program.
Here is my program so far.
____________________________________________
#!/usr/bin/perl
@endpipe = ("run program", 16, 2, 1, "y", "q", "y", '/r');
foreach $endpipe (@endpipe) {
system "$endpipe &";
}
_____________________________________________
The run program part starts the app fine. But the next menu option (16) doesn't get selected.
This is running inside a k shell on AIX if that makes any difference. Any ideas on how to get this to work? Sorry if this is an easy question, I'm still new to perl.
Thanks,
Mike
|
|
|
12-03-2004, 03:54 PM
|
#2
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
perldoc -tf open specifically, the part about opening pipes to other programs.
If you need to write *and* read to a process, see man perlipc
|
|
|
12-04-2004, 04:35 PM
|
#3
|
LQ Newbie
Registered: Aug 2003
Posts: 6
Original Poster
Rep:
|
I looked through the docs, and I'm still not finding it. I tried to open the program as a process with a leading pipe and then printing to the process, but all subsequent writes have the initial command sent. open (UPIPE, "|run unix") does open the program though. Here is where I left off.
_______________________________
#!/usr/bin/perl
@endpipe = ("run unix", 16, 2, 1, "y", "q", "y", '/r');
foreach $endpipe (@endpipe) {
open (UPIPE, "|$endpipe") || die "cant open program: $!";
close UPIPE;
}
_______________________________
I've tried numerous different combinations. Any idea's on what I need to try? I figured opening a program and selecting a few menu options (mimicking keystrokes) would be fairly easy. Man, was I wrong.
|
|
|
12-05-2004, 03:16 PM
|
#4
|
Senior Member
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197
Rep:
|
Code:
#!/usr/local/bin/perl -w
# Set the program to run
$progName = "run unix";
# Set the things to pipe to the program
@args = ("16", "2", "1", "y", "q", "y", "\r");
# If the program expects "enter" after the commands, you'll need this instead.
# @args = ("16\n", "2\n", "1\n", "y\n", "q\n", "y\n", "\r");
# Open a file handle to the program
open(UPIPE, "|$progName") or die("Can't open $progName: $!");
# Select UPIPE as the handle we want to print to
select(UPIPE);
# Pass in the arguments
foreach (@args) {
# Since we have UPIPE as the default output hande, and print
# operates on $_ in the absence of parameters, just print();
print;
}
close(UPIPE);
Try that. If it's not self explanatory, just ask.
|
|
|
12-08-2004, 12:59 PM
|
#5
|
LQ Newbie
Registered: Aug 2003
Posts: 6
Original Poster
Rep:
|
I'll try that. I appreciate you taking the time to help and I'll let you know how it works out.
Thanks.
|
|
|
All times are GMT -5. The time now is 02:58 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|