LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 12-03-2004, 03:38 PM   #1
MWFlint
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Rep: Reputation: 0
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
 
Old 12-03-2004, 03:54 PM   #2
sigsegv
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: Reputation: 47
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
 
Old 12-04-2004, 04:35 PM   #3
MWFlint
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Original Poster
Rep: Reputation: 0
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.
 
Old 12-05-2004, 03:16 PM   #4
sigsegv
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: Reputation: 47
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.
 
Old 12-08-2004, 12:59 PM   #5
MWFlint
LQ Newbie
 
Registered: Aug 2003
Posts: 6

Original Poster
Rep: Reputation: 0
I'll try that. I appreciate you taking the time to help and I'll let you know how it works out.

Thanks.
 
  


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
Program to control volume from console? enemorales Linux - Software 2 02-17-2005 12:28 PM
howto control a perl script by a hardware switch jujo Linux - Software 0 08-17-2004 03:24 PM
How to fully control a program within another program marri Programming 5 07-28-2004 09:04 PM
Slackware control panel program? neilcpp Slackware - Installation 3 01-28-2004 10:17 PM
first perl program --need feedback farhanali Programming 5 08-04-2003 08:23 PM

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

All times are GMT -5. The time now is 09:14 AM.

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