Problem with C pipes [reprise]
Posted: Sat Jul 20, 2013 6:29 am
Hi Paul,
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:
When I try this using a pipe to pipe routine in c (MinGW32 gcc 4.6.1) I get the following messages:
I am guessing that for some reason, the aescrypt on the decryption side of the pipe appears not to have access to STDOUT. However, the "ls" command piped to "SORT" does work through the same C function.
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:
And here is the function I am using:
Any further light you can shed on this would be appreciated.
Regards,
Gary
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