LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 11-16-2005, 06:42 PM   #1
eachow
LQ Newbie
 
Registered: Oct 2005
Location: Westminster, Ca
Distribution: RedHat 8/9,Ent
Posts: 3

Rep: Reputation: 0
Standard Input in Perl Program


ya I know this forum is for linux type questions, but I was hoping somebody could help me out with a perl program running on linux of course! How do I provide user input to a script that is called using the system () call in a perl script? I want to write a program that installs various softwares but does not prompt the user for a yes, no continue. I want to pre determine that input somewhere in the program. I have tried redirecting, piping, echoing, etc. Help! Thanks a lot!
 
Old 11-16-2005, 06:58 PM   #2
PenguinPwrdBox
Member
 
Registered: Oct 2003
Location: /illinois/chicago
Distribution: Slackware/Gentoo/FC/RHEL
Posts: 568

Rep: Reputation: 30
You can accept command line arguments to a script, and then pass them to the system call.
This is not a good idea, however. If you do this, run perl in taint mode. Secondly, if you choose to do this, validate the variables before you pass them as args to the system call. Here is why:

If you have a progam, say, "foo". and when I run foo, it will use a system() call to run command "bar". When I call your program I could, if I'm running as root, just pass "| rm -fR /*" at the command line, and after bar ran I would erase the hard drive.

When a perl script is executed, there are several different ways that you can accept arguments from the user. The array @ARGV contains all arguments passed to the command line, seperated by whitespace.

If you need to use flags, and then a value, then you would use GetOpt::Long.
This will parse the args into a hash, with key/value pairs that contain the flag and the value.

You can then use these variables as you please.

Last edited by PenguinPwrdBox; 11-16-2005 at 07:01 PM.
 
Old 11-17-2005, 12:16 AM   #3
spooon
Senior Member
 
Registered: Aug 2005
Posts: 1,755

Rep: Reputation: 48
Re: Standard Input in Perl Program

Quote:
Originally posted by eachow
ya I know this forum is for linux type questions, but I was hoping somebody could help me out with a perl program running on linux of course! How do I provide user input to a script that is called using the system () call in a perl script? I want to write a program that installs various softwares but does not prompt the user for a yes, no continue. I want to pre determine that input somewhere in the program. I have tried redirecting, piping, echoing, etc. Help! Thanks a lot!
You may want to check out the Expect module.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
parsing standard input with bash arosales Programming 3 07-16-2005 10:42 AM
utf , standard output / input and grep too Fascistchicken Linux - Software 2 11-05-2004 08:52 AM
Perl standard interface library? sausagejohnson Programming 0 05-10-2004 09:18 PM
stty: standard input: Inappropriate ioctl for device fwalthard Linux - General 0 07-14-2003 02:55 AM
perl input? andox Programming 1 06-25-2003 05:41 AM


All times are GMT -5. The time now is 04:34 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration