Sponsored Content
Full Discussion: Pipe error
Top Forums Programming Pipe error Post 302474157 by Praveen_218 on Tuesday 23rd of November 2010 12:34:54 PM
Old 11-23-2010
Here are some of the errors, you may correct to improve your program ...

Quote:
Originally Posted by beandj
Code:
3include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int main(){
 

     int pos;
     char leitor[1000];
     char reader[1000];

    FILE *arq, *arq1, *arq2;
     arq = fopen("teste.txt","r");
        arq1 = fopen("arquivoPai.txt","w+");
        arq2 = fopen("arquivoFilho.txt","w+");


     pipe(fp);
     pipe(pf);
     pid_t pid;
     pid = fork();

    pos = ftell(arq);
       while(!feof(arq))
     {
             if(pid == 0 && (pos%2)==0)
          {
               
               close(fp[0]);
               close(pf[1]);
               read(pf[0], reader, sizeof(reader));
               fprintf(arq1,"%s \n",reader);
               fscanf(arq,"%s",leitor);
               write(fp[1],leitor, (strlen(leitor)+1));
          }
  
             else
          {
  
               close(fp[1]);
               close(pf[0]);
               read(fp[0],reader, sizeof(reader));
               fprintf(arq2,"%s \n",reader);
               fscanf(arq,"%s",leitor);
               write(pf[1],leitor,(strlen(leitor)+1));

          }

      pos = ftell(arq);
     }
 
     exit(0);
     fclose(arq);
     fclose(arq1);
     fclose(arq2);
 

return 0;
}

i dont know how to create a two-way pipes

i need to send father-to-child a pair line of teste.txt
and send child-to-faher a odd line of teste.txt

and i need to print in two diferent .txt

but the program do nothing
There are atleast 3 errors, I could figure out. They are following:

1) You have not declered & defined pf,
2) You have not declered & defined fp,
3) You have not initilize pos; its using a garbage value.

The worst part is that you are controlling the program flow using and AND condition with (pid == 0) && (pos % 2 == 0). You are taking the mod of a garbage value, isn't it?

Now could you please try to analyse the result of that if() expression for the below two cases:
1) When pos has a garbage value which is an odd number,
2) When pos has a garbage value which is an even number

I think its pretty enough for you to know what went wrong.

Also, just declare & define pf and fp as below:
Code:
int pf[2], fp[2];

Rest is okey in your program.
 

10 More Discussions You Might Find Interesting

1. AIX

broken pipe error

Hi, I am working on AIX 5.3 . I have client-server program which is in ProC.while sending packet to server i am getting error as broken pipe and program exiting. please help?/? (1 Reply)
Discussion started by: ajaysahoo
1 Replies

2. Programming

gzip on pipe error handling

Hi all... I have the following code: FILE *fp = popen(" gzip -dc /somemount/somefile.gz", "r"); while(fgets(buffer, 1024, fp)) { some code.... } "/somemount" is a mount of some network drive. Sometimes error occurs in while loop - I can see the following "Input/Output error"... (4 Replies)
Discussion started by: adm1n
4 Replies

3. Programming

Broken Pipe error

All, I am using the below code The C code : if ((fp2=fopen(szout_fname,"r"))==NULL) { sprintf(stream_ptr1,"cat %s | sort -t, -rn -k 11,11 | awk -F\",\" '{ \ if ( \$3 ==\"%s\" ) {print... (0 Replies)
Discussion started by: arunkumar_mca
0 Replies

4. UNIX for Dummies Questions & Answers

echo: write error: Broken pipe ??

I want to try the unix pipe, the command is like this: echo new | find . the standard output of the echo should be "new", then I guess find command will use this output as input to find the file named "new". But the output is all the file names in my current dir, the last line is "echo: write... (5 Replies)
Discussion started by: andrewust
5 Replies

5. Shell Programming and Scripting

Broken Pipe error

Hello while doing sftp over server "A" , i am getting a broken pipe error i.e cat: write error: Broken pipe what does that mean? please let me know if you want any other info on this.. (3 Replies)
Discussion started by: urfrnddpk
3 Replies

6. UNIX for Dummies Questions & Answers

broken pipe error

I'm new to scripting, and this forum has been invaluable in helping me out. I'm hoping I can get some personal help now though. I have a korn script that takes a list of servers and either telnets or sshs into it (only some are set up for ssh). What I'm doing now is trying to telnet first, and... (10 Replies)
Discussion started by: aimeet
10 Replies

7. Shell Programming and Scripting

Pipe causing last command error to not function

Hi I am quite new to scripting and cannot work out how to do the following - I want to pipe to a log file and then use the "last statement error" in an if statement after, and this doesn't work because it checks the pipe statement instead of the script. Example: executteTheScript $var |... (4 Replies)
Discussion started by: erjorgito
4 Replies

8. Shell Programming and Scripting

Capture error before pipe

Hi, I have a script that runs a tar command to standard out then pipes to a gzip: tar cfE - * | gzip -c > OUT.gz At the moment, even if the tar fails (e.g. because of lack of disk space), the gzip still runs successfully. Is there a way to make the whole line exit with a non-zero error... (6 Replies)
Discussion started by: Catullus
6 Replies

9. Shell Programming and Scripting

Pipe, permission denied error

Hello, I am trying to stream lines written into file. When first source is down, I expect the code to swap to second line and run it. Script below works as usual and it prints out each line of the input file (s.txt): #!/bin/bash while read -r line; do echo "$line" done <"$1" exit 0Output... (12 Replies)
Discussion started by: baris35
12 Replies

10. Programming

Pipe usage error while visiting directories

To begin with FYI, I really struggled with the question before asking to simplify as much as I can around 1 hour and to increase the code's readability I neglect error checks. I intend to communicate parent and child using PIPE. In the following program I do traverse given path and its... (2 Replies)
Discussion started by: beginnerboy
2 Replies
FLARQ(1)																  FLARQ(1)

NAME
flarq - ARQ data transfer utility for fldigi SYNOPSIS
flarq [OPTIONS] DESCRIPTION
Flarq (fast light automatic repeat request) is a file transfer application that is based on the ARQ specification developed by Paul Schmidt, K9PS. It is capable of transmitting and receiving frames of ARQ data via fldigi, as well as MultiPSK on Windows. OPTIONS
Long options begin with two hyphens and are handled by flarq. The option names may be abbreviated to any unambiguous substring, and the option argument may be separated from the name by a space or equals sign, as per getopt(3). Short options begin with a single hyphen and are passed directly to FLTK. They may be abbreviated only as indicated. --arq-protocol TYPE Set the ARQ protocol. May be either "fldigi" or "multipsk". Defaults to "fldigi". --arq-server-address HOSTNAME Set the ARQ TCP server address. Defaults to "127.0.0.1". HOSTNAME may be any node name string accepted by getaddrinfo(3). --arq-server-port PORT Set the ARQ TCP server port. Defaults to "7322". PORT may be any service name string accepted by getaddrinfo(3). --debug Enable debugging messages. --version Print version information and exit. --build-info Print build information and exit. --help Print options summary and exit. Standard FLTK options -bg, -background COLOUR Set the background colour. -bg2, -background2 COLOUR Set the secondary (text) background colour. -di, -display DISPLAY Specifies the X server to connect to; see X(7). -dn, -dnd or -nodn, -nodnd Enable or disable drag and drop copy and paste in text fields. -fg, -foreground COLOUR Set the foreground colour. -g, -geometry GEOMETRY Set the initial window size and position. Flarq may not honour this option. -i, -iconic Start flarq in iconified state. Flarq may not honour this option. -k, -kbd or -nok, -nokbd Enable or disable visible keyboard focus in non-text widgets. -na, -name CLASSNAME Set the window class. Defaults to "Flarq". -ti, -title WINDOWTITLE Set the window title. Defaults to "flarq - <callsign>". Additional UI options --font FONT[:SIZE] Set the widget font and (optionally) size. Defaults to "sans:12". FILES
$HOME/.flarq The main settings file. The following directories are used to interface with MUAs such as Sylpheed: $HOME/Mail/ARQin Stores incoming email messages. $HOME/Mail/ARQout Stores outgoing email messages. $HOME/Mail/ARQsent Stores sent email messages. The following directories are used for ARQ file transfer: $HOME/ARQrecv Stores received files. $HOME/ARQsend Stores files to be transmitted. $HOME/ARQfiles/logfile.txt Stores transfer logs. BUGS
o There are no command line arguments to override the default configuration file and ARQ and Mail directories. SEE ALSO
fldigi(1), getaddrinfo(3), getopt(3), X(7) RESOURCES
Flarq web site: http://www.w1hkj.com/flarq_main.html Fldigi web site: http://www.w1hkj.com/Fldigi.html BerliOS project page: http://developer.berlios.de/projects/fldigi/ ARQ specification by Paul Schmidt, K9PS: http://www.w1hkj.com/FlarqHelpFiles/ARQ2.pdf AUTHORS
Flarq was written by David Freese, W1HKJ. This manual page was written by Stelios Bounanos <sb[at]enotty(dot)net>. COPYING
License GPLv3+: GNU GPL version 3 or later. 07/01/2012 FLARQ(1)
All times are GMT -4. The time now is 05:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy