PDA

View Full Version : Perl question


eagle683
07-08-2005, 12:28 AM
Hey all,

I am fairly new to Perl, and I am in the process of writing a program that controls another shell program (similar to ftp), and I need to both control it using perl, and have the program react to messages such as, "permission denied" if I can't make a directory on a certain computer. Alternatitvely, is there a way I can check that it worked using the program.

The problem I am mainly encountering, is I can control the program to do whatever at the moment; however, I cannot read the output, so it just becomes stuck. The program is in its beginning stages, so I am really open to do anything with it right now.

Thanks for any help in advance.

eagle

eagle683
07-08-2005, 12:32 AM
Just in case...

I'll put some code in to show that I have actually worked at it.

if I use open name, "| prog" or die blalblablabla

I can control the program, but can't read its output

if I use open name, "prog |" or die blalbblalbla

I can read its output, but I can't control the program.
I am looking for a way to do both.

Again, thanks for any help in advance.

eagle

Antoniohawk
07-08-2005, 03:18 AM
Sounds a lot like a Perl issue. Heading this over to Perl/CGI section.

netroact
07-08-2005, 06:51 AM
I could be wrong, but if it was me, I would probably just lose the shell scripts, and just control everything from your Perl script using some version of Net::FTP

http://search.cpan.org/search?mode=module&query=Net::FTP

Oops! I just noticed that FishMonger said it already on the other post.

FishMonger
07-08-2005, 07:44 AM
As you have descovered, openning a pipe to an external program as you have done won't work. If you're really set on doing it the hard way with the 2 seperate scripts, you' can look at using IPC::Open3 http://search.cpan.org/~nwclark/perl-5.8.7/lib/IPC/Open3.pm

However I still recommend, as does netroact, that you drop the shell script and do everything in the Perl script.

FishMonger
07-08-2005, 08:02 AM
Another option is to use IO::Socket

http://search.cpan.org/~nwclark/perl-5.8.7/ext/IO/lib/IO/Socket.pm