Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Providing Input to an executable that is invoked from perl script

Status
Not open for further replies.

prasannakiran

Programmer
Joined
Dec 28, 2006
Messages
2
Location
US
Hi,
I am new to perl and need help in the below situation

I have a C language executable called myprogram and i am calling it from my perl script test.pl.My OS is linux.
below is the code for test.pl

_______________________________________________________

Code:
#!/usr/local/bin/perl
$command = "make";
system("$command");
chdir("/mydir");
$command = "./myprogram";
system("$command");
_________________________________________________________

here the executable myprogram is an interactive program.
When i run, it asks to enter the user name first and then regristration number.So when i try to execute from the perl script, it is running fine and asking the user input.At present i am giving it manually..But i have to automate that process also..I am not getting how to provide input to that through perl script...Any help??

Thanks in Advance
PK




 
Input to a Perl script can usually come from one (or more) of three sources:
- input from the keyboard
- parameters passed to the script (via @ARGV) - data or names of files
- information by reading files

It is also possible to write the script so that if information is not present where it is expected then another source is used (or prompted for).

I hope that helps.

Mike
 
Mike,
my question is my script test.pl should provide input to the interactive program myprogram.When myprogram is running, the input should be provided by a perl script..
 
Check if your program accepts command line arguments. Many programs have options for providing input from the command line or switches that can be set to automate processes like you are trying to do.

- Kevin, perl coder unexceptional!
 
If myprogram reads from STDIN, you can pipe the input in to the command. Maybe write a temp file from perl with the commands in it, then
Code:
system('./mycmd < tempfile.txt');
or even
Code:
my @results = qx{./mycmd < tempfile.txt};
if you need to capture the output.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top