LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Standard Input in Perl Program (https://www.linuxquestions.org/questions/linux-general-1/standard-input-in-perl-program-383824/)

eachow 11-16-2005 06:42 PM

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!

PenguinPwrdBox 11-16-2005 06:58 PM

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.

spooon 11-17-2005 12:16 AM

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.


All times are GMT -5. The time now is 08:26 AM.