By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,852 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,852 IT Pros & Developers. It's quick & easy.

Capturing text printed on console

P: 33
Hello,
I want to capture the text being printed on console.
problem description is as follows.
I am calling called.pl program from caller.pl program using backticks.
in called.pl program i am giving an external command to be executed in backticks.
that external application will through a message to the console if any arguements are missing for that command.
for example if we are not sending username and password(or wrong username and password) which will be validated by that external program and if they are not found, it will through a message to console.
i want to capture that message and based on that message i need to trigger some events.
presently i am not able to capture any console text other than print stmts in external program which is called from called.pl using backticks.
can anybody help me in capturing that text.

thanks in advance.

regards,
Mohan.
Apr 2 '08 #1
Share this Question
Share on Google+
3 Replies


KevinADC
Expert 2.5K+
P: 4,059
your premise is just wrong from the get go. You don't want to try an capture console output, you want to write a function into your script that does something if the user input is incorrect. Now there is a module that communicates with the standard output of applications, Expect, and you can tell your perl program to do stuff by parsing the output using the Expect module, but I don't know if that will work for you or not. You can look into it though and see if it will. I think it will need to be installed though.
Apr 2 '08 #2

P: 33
Hi kevin,
Thanks for your reply.
I am working in windows machine where i dont have permissions to install any modules.
As i observed Expect.pm is not present in ActivePerl core distribution.
here my concern is to capture the output printed by that external program (for example .. "You do not have sufficient privileges..").
But as i observed is that with Expect module we can spawn a child and control it with in our program like we will through a user defined message if the spawning of the program fails... but not the error message returned by the external program.
Please suggest me can i achieve it in any other way.
Please correct me if i am wrong.

Thanks,
Mohan.


your premise is just wrong from the get go. You don't want to try an capture console output, you want to write a function into your script that does something if the user input is incorrect. Now there is a module that communicates with the standard output of applications, Expect, and you can tell your perl program to do stuff by parsing the output using the Expect module, but I don't know if that will work for you or not. You can look into it though and see if it will. I think it will need to be installed though.
Apr 2 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
Well, I don't think Expect even works on Windows unless maybe you install cygwin. My suggestion is you look into one of the Win32 modules that comes with your distribution of ActivePerl. There might be one that does this very thing but I do not know of one off the top of my head. So search through all the Win32 modules documentations and see if you get lucky.

Or maybe someone else will know of something.
Apr 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.