Find the answer to your Linux question:
Results 1 to 7 of 7
I have build a little xlib/ motif program and try to read from stdin as was it a usual C-programm. I try to use fgets... But it seems not to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2013
    Posts
    19

    Read from stdin - not keyboard - in Xlib // Motif


    I have build a little xlib/ motif program and try to read from stdin as was it a usual C-programm.
    I try to use fgets... But it seems not to get any input.
    My guess is the motif program is reading from the keyboard.
    What do I have to do to get the program read from the stdin which is in fact the output from a pipe.

    i.e. cat file | motif-program

    Any help is apreciated. I realy could no find a solution.

  2. #2
    Linux User
    Join Date
    Dec 2011
    Location
    Turtle Island West
    Posts
    395
    I could be wrong, because I have no idea what the code of your motif program looks like, but I'm sure you'll need to post some code so that someone can see what you are actually trying to do.

    Peace and Cheer.

  3. #3
    Just Joined!
    Join Date
    May 2013
    Posts
    19
    Hi Miven, well it does not much matter what the code is, its about the way to do.
    Just opening "stdin" whch is currently the keyboard does noet work, reopen of the "stdin' also does not work.
    When I open a filedescriptor "3" with fdopen and fill the pipe with output with exec 3<&1 the recieving program blocks.

    I think I need a named pipe ?

    Also, I think bash does the repiping wrong, because :
    Code:
    exec 5<&1
    echo "TEST" >&5
    exec 5>&-
    puts TEST on the screen, while it shuold go to the pipe, just created.

  4. #4
    Just Joined!
    Join Date
    May 2013
    Posts
    19
    This is a small example, maby it helps to understand what I want to do :
    Code:
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <stdlib.h>
    #include <string.h>
    
    FILE *fp;
    
    main (int argc, char *argv[])
    {
       char s[257];
    
       fp = fdopen(3,"r");
    
       while(1)
       {
          fgets(s,255,fp);
          if(s[0] == EOF)exit(1);
          printf("<<%s>>\n",s);
       }
    
       fclose(fp);
    
    }
    Using this with the pie example above, all output is from the cat and not from the printf.
    Last edited by kuifje; 05-11-2013 at 01:17 PM. Reason: Typo corrected ( while(0) > while(1) )

  5. #5
    Just Joined!
    Join Date
    May 2013
    Posts
    19
    Okay, i tried using a named pie, that works fine.
    mkfifo -m 666 /tmp/pipe
    cat "file" 1>/tmp/pipe
    Then let the program read from the pipe.

    Any better idea's ?

  6. #6
    Just Joined!
    Join Date
    May 2013
    Posts
    19
    Well, this is not the best idea I just found out.
    While there is plenty of cpu time and no wait-io , my set-up does not work well.
    It is very slow, and unusable.

    Named pipe are slow ( because of the filesystem io ? ) but this slow, I did not expected.

    So there must be a better way to pipe the ouput of one to a motif program, because motif listens default to the keyboard.
    Or am I just being mislead?

  7. #7
    Just Joined!
    Join Date
    May 2013
    Posts
    19
    Quote Originally Posted by kuifje View Post
    Well, this is not the best idea I just found out.
    While there is plenty of cpu time and no wait-io , my set-up does not work well.
    It is very slow, and unusable.
    Found the reason of being slow. I used a timer with the wrong value. Thats why there was no io-wait. Its fine now.

    Although, if there is a way to not use a named-pipe. ny idea is very welcome.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •