LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-23-2004, 01:27 AM   #1
phil123
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Rep: Reputation: 0
first program | my program


the first program is real-time output program, how "my program" real-time read the redirect output from "first program"? loop read the argv[1]?can somebody write a simple code in follow... thanks
 
Old 02-23-2004, 02:59 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
pleas explain your query in a more coherent manner... and provide more real details, what language are you using etc...
 
Old 02-23-2004, 01:42 PM   #3
phil123
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Original Poster
Rep: Reputation: 0
detail

the "first program" realtime output pixel data to standardout, I wish "my program" can dealwith these pixel data then output to standardout.
I use c++ on Red hat 9.0.
the problem is I am not sure how to realtime read these input data. How to open and read the pipe, " | ", in my program? just read argv[1]? how to ensure realtime.
 
Old 02-23-2004, 02:44 PM   #4
chewysplace
Member
 
Registered: Sep 2003
Distribution: Slackware 10 w/ Kernel 2.6.8
Posts: 176

Rep: Reputation: 30
#1: what "standardout" are you using? are you outputing to a file? to the screen? where is the output going?

#2: have you thought about combining the code to make one program that does all this?

#3: how is you pipe, "|", defined? what is your pipes purpose in the program? does it process input, output or both?
 
Old 02-23-2004, 02:57 PM   #5
phil123
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Original Poster
Rep: Reputation: 0
good question,

1, the stdout points screen
2, i wish it can combin in one program, but "first program" should be any specifed file, no source code. I once use this way:
dup2(fds[0],stdout_fileno);
execlp("first program","first program", NULL);

however, it cannot work. I think the reason is firt program take place the current program. Do you have idea to do the output redirecting in proram.
3,"|" points shell command redirecting. you know, I try to use shell comand to do the above work.
 
Old 02-23-2004, 06:32 PM   #6
chewysplace
Member
 
Registered: Sep 2003
Distribution: Slackware 10 w/ Kernel 2.6.8
Posts: 176

Rep: Reputation: 30
i think you might be confused as to what stdout deals with. here is a link that better explains the usage of stdout with many extra references:
http://www.wlug.org.nz/stdout(3)

So "first program" is not realy a program at all, it's just a file?
If "first program" is just a file name, try setting a character string to it:

#include<string.h>

char FileName[256];
strcpy(FileName,"first program");

using FileName[256] allows you to copy another file name over if "first program" is not the file you wish to use anymore.

Something for you to play with:

#include<string.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argv, char argc)
{
char *shellCommand = "xterm";
system(shellCommand);
}

This executes an XTerminal. You can change the shellCommand to what ever you need. Maybe make a whole bunch of pointers to shell commands. Then use a case statement to decide what command needs to be used.

Enjoy
 
Old 02-24-2004, 03:35 PM   #7
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
In the '<first program> | <my program>' example, the output from <first program> is sent to <my program> through stdin.

So to read the output from <first program> you'd write your program something like this:
Code:
int main(void)
{
  char *buf = NULL, inp[256];
  int size = 0, n;

  while(fgets(inp, sizeof(inp), stdin))
  {
    n = strlen(inp);
    size += n;
    buf = realloc(buf, size+1);
    memcpy(buf+size, inp, n);
  }

  // 'buf' now holds all of the output from <first program>
}

Last edited by itsme86; 02-24-2004 at 03:37 PM.
 
Old 02-25-2004, 02:35 AM   #8
phil123
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Original Poster
Rep: Reputation: 0
you are right,but

I also can get from argv[1].
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sms program and database in linux web program in windows.. does not see each other.. keikun_naruchan Programming 0 07-06-2005 01:40 AM
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
Stop java program(threaded program..should end cleanly) rmanocha Programming 4 11-09-2004 09:36 AM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration