Reading or Writing to Another Program in Python

Hello Team,

I am AIX Administrator and fresher in Python. I have installed new python version on my AIX test server. i want to write a program in python which help me to transfer data from one server to other server without any third party tool.

i found one link which help us to read and write data in perl. (docstore.mik.ua/orelly/perl/cookbook/ch16_05.htm. But when I tried it in python, then it is not working properly.

Here my idea is whenever my system will start mksysb backup (System backup) through python program (I wrote command in my program which is working properly), But i want to transfer data at the same time to other system through PIPE device in python.

Is it really possible?
could you please give me some idea. I didnot write any code to transfer data through PIPE. Because I really dont know how it works. on net i got many sites which tells chatting related program which is not helpful for me.

Thanks and Regards,
Dipti Kotawadekar

Hi Dipti,

  • everything is possible :slight_smile: .

May I ask: of which kind is your data? Do you want to transfer files to other Computers? Might FTP be an option? If so, have a peek here:

Python FTP programming - Python ftplib (zetcode.com)

Cheers, Dominik

Hello Dominik,

Thank you for your reply.

This is stream data.

i have one perl program, which uses fork & named pipe,
on the host, parent fork: using SSH, backup command writes stream data directly to a pipe device (created by mknod) & child fork: reads the pipe device using cat & redirects data to a file.

Here is some part of my program.

my %pid;
if ( ( $pid{write} = fork()) == 0 ) {
print “*** starting system backup “;
print “DEBUG: $ssh $host ‘sudo $sys_backup $pipe 2>&1’\n” if $debug>0;
exec(”$ssh $host ‘sudo $sys_backup $pipe 2>&1’”);
exit;

}
else {
print “*** sys_backup-process started: $pid{write}\n”;
print “*** reading remote pipe ($pid{read}):\n”;
print “DEBUG: $ssh $host ‘$cat $pipe 2>/dev/null’ > $target |” if $debug>0;
$pid{read}=open(SSH2,"$ssh $host ‘$cat $pipe 2>/dev/null’ > $target |") ;
while () {
print “$_\n”;
}
close (SSH2);
my $rcrp=$?;
waitpid($pid{write},0);
print “*** reading pipe RC=$rcrp\n”;
$pid{write}=“undef”;
$rcread=$?;
print "*** sys_backup rc=$rcread ";
if ($rcread != 0) {
print “*** ERROR\n”;
kill => $pid{read};
exit 5;
}
}

Thanks and Regards,
Dipti Kotawadekar

Hi Dipti,

would you be so kind to use the “</>” (“preformatted text”) to insert code - otherwise it is quite hard to read…

You might use socket.socket(…) - e.g. have a look at:

Socket Programming in Python (Guide) – Real Python

Cheers, Dominik

Hello Dominik,

Thanks for an update. Let me try something with given link.

Regards,
Dipti Kotawadekar

1 Like