Thanks for your quick response to my first post, and sorry for the confusion over examples I gave.
Appears my edit of this topic got swallowed up somewhere:
Here is the abridged version:
I am trying to pipe the output of one aescrypt decryption to the input of an aescrypt encryption.
This works fine as a DOS batch command on windows7 thus:
Code: Select all
aescrypt -d -p password1 -o - infilename | aescrypt -e -p password2 -o outfilename -
Code: Select all
Error writing decrypted block:: Invalid argument
I have tried every combination of syntax and buffer sizes I can think of, but still get the same result.
These are the values of the two variables I pass to pipe2pipe:
Code: Select all
cmd1="aescrypt -d -p password1 -o - infilename"
cmd2="aescrypt -e -p password2 -o outfilename -"
Code: Select all
#include <stdio>
#define MAX_PIPE_BUFF 128
int pipe2pipe(char *cmd1, char *cmd2)
{
// -----------------------------------------------------------------------------
// Open two pipes allowing output from one command to be piped to the other
// -----------------------------------------------------------------------------
FILE *pipein_fp, *pipeout_fp;
char readbuf[MAX_PIPE_BUFF];
long bytes;
// pipe IN
if (( pipein_fp = popen(cmd1, "r")) == NULL)
{
perror("popen");
return(1);
}
// pipe OUT
if (( pipeout_fp = popen(cmd2, "w")) == NULL)
{
perror("popen");
return(1);
}
while( (bytes=fread(readbuf,sizeof(readbuf),1,pipein_fp))>0)
fwrite(readbuf,bytes,1,pipeout_fp);
// Clean up
pclose(pipein_fp);
pclose(pipeout_fp);
return(0);
}
Regards,
Gary