954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Passing parameters to a system call

Ok. I am trying to write a perl program to automate installation of certain softwares (as root) on a linux machine. I want my perl program to call an installation script and provide parameters to that script such that I do not have to enter 'yes', 'no', 'continue', create directory?', etc, from the command line. I want to fully automate the installation process without much user interaction via keyboard. I need help. Thanks

eachowcc
Newbie Poster
3 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 
Ok. I am trying to write a perl program to automate installation of certain softwares (as root) on a linux machine. I want my perl program to call an installation script and provide parameters to that script such that I do not have to enter 'yes', 'no', 'continue', create directory?', etc, from the command line. I want to fully automate the installation process without much user interaction via keyboard. I need help. Thanks

To call another program with parameters, you will want to pass a list of parameter strings to the 'system' function.

E.g.

system "cp", "foo", "bar";


See http://www.unix.org.ua/orelly/perl/prog3/ch29_02.htm#INDEX-5326

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

To call another program with parameters, you will want to pass a list of parameter strings to the 'system' function.

E.g.

system "cp", "foo", "bar";

See http://www.unix.org.ua/orelly/perl/prog3/ch29_02.htm#INDEX-5326

Thanks, but what if the program I am calling within my perl script does not take command line arguments? Rather, what if the program I call within my perl script simply outputs a "Create directory?" question where it expects input from the user, rather than a paramter such as "cp foo bar"? I tried echo'ing and piping, and such. Help???

eachowcc
Newbie Poster
3 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

You need to look at expect rather than trying to use perl.
expect is used for automating interactive dialogues.

jim mcnamara
Junior Poster
180 posts since May 2004
Reputation Points: 62
Solved Threads: 10
 

Thanks. It sounds familiar. I will look into it!

eachowcc
Newbie Poster
3 posts since Nov 2005
Reputation Points: 10
Solved Threads: 0
 

Don't be silly. Open the process with a file handle, and you can write data to it that way. For instance:

# /* Open The Program (Just Like A File) Piping Data To It (For Writing) */
open (FH, "| /path2/install/program");

     # /* Actually Write To The Process */
     print FH "Y\n";

close(FH);


It will obviously be more complicated than that... but if you change the path and program to your install program, and follow through it step by step, you'll be good to go.

Comatose
Taboo Programmer
Team Colleague
2,910 posts since Dec 2004
Reputation Points: 361
Solved Threads: 215
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You