help with capturing output of open command 
Author Message
 help with capturing output of open command

I have a piece of code that looks something like below:

   LOG ("Opening ftp connection to $server...");
   open (FTP, "|lftp $server\n");
   LOG ("Logging in as user $username...");
   print FTP "user $username $password\n";
   die unless defined ($pid = print FTP "ls $remote_dir\n");
   waitpid ("$pid", 0);
   LOG ("Making remote directory \"$remote_dir\"...");
   print FTP "mkdir $remote_dir\n";
   print FTP "cd $remote_dir\n";
   LOG ("FTP files from \"$upload_dir\" to \"$remote_dir\"...");
   print FTP "lcd $upload_dir\n";

   #$cmd = "mput *";
   die unless defined ($pid = print FTP "mput *\n");
   waitpid ("$pid", 0);
   close (FTP);

How do I capture the output of all the commands that I send to the FTP
handle?  I'm new at Perl, so Please help.

thank you

Sent via Deja.com
http://www.*-*-*.com/



Sat, 12 Jul 2003 11:15:26 GMT  
 help with capturing output of open command

Quote:

> I have a piece of code that looks something like below:

(snipped unqualified code)

How do you expect people to help if
you do not post actual code? This
"looks something like" is a rather
innane way of displaying your code
or I should say, not displaying.
Post your actual code snippet, not
some pseudo facsimile of unqualified
accuracy.

Quote:
> How do I capture the output of all the commands
> that I send to the FTP handle?

Print them to a log record.

Godzilla!



Sat, 12 Jul 2003 12:17:41 GMT  
 help with capturing output of open command

Quote:

>I have a piece of code that looks something like below:

>   LOG ("Opening ftp connection to $server...");

Where is the definition of LOG()?  

Quote:
>   open (FTP, "|lftp $server\n");
>   LOG ("Logging in as user $username...");
>   print FTP "user $username $password\n";
>   die unless defined ($pid = print FTP "ls $remote_dir\n");
>   waitpid ("$pid", 0);

Have you checked perlfunc to see what the print function returns?  I
guess not because it's _not_ a process ID.  

Since you seem to want to communicate with an FTP server from your
code, I would recommend that you consider the Net::FTP module.  It
will make life a lot easier.  

[ snip similarly confused code ]

Quote:
>How do I capture the output of all the commands that I send to the FTP
>handle?  I'm new at Perl, so Please help.

I first thought about IPC::Open2(), but...

The Net::FTP module will log lots of information for you, if you ask
it.  But better still, its methods will communicate the results of
commands sent to the server.  Check the Net::FTP manual page.  The
Net::FTP module *really* is what you want.  

--
Garry Williams



Sat, 12 Jul 2003 12:25:37 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help with Piped command, capturing output

2. capturing command line error or output from `<command>`

3. capturing output of FILEHANDLE "| command"

4. capturing output from a remote command (how?)

5. Capturing System Command Output with Perl on Windows/Apache

6. capturing output of executed system command

7. capturing output of piped commands

8. Capture command output into list?

9. Capturing output of a system command

10. How do I capture output from a print command

11. Capturing command output in Perl

12. Capturing Command Line Output

 

 
Powered by phpBB® Forum Software