Hi Urgent


 
Thread Tools Search this Thread
Top Forums Programming Hi Urgent
# 1  
Old 05-27-2008
Hi Urgent

Hi

Im launching another applicaTION from my "C" program.
Is there any way to capture the application output only.

Example.

printf ("U have pressed 1\n");
system("ls -l");
printf (" U have launched a command\n");


Any way to capture only output from the system ("ls -l") command.
Other 2 printf statements should be print on the terminal.
# 2  
Old 05-27-2008
You need to call popen(), not system. Check the man page for popen.

This link has a code example using an ls call with popen
popen
# 3  
Old 05-27-2008
popen is only used to execute a shell command.
But how to capture through tee command which is built in C.
vmsplice or splice.

Thanks in advance
# 4  
Old 05-27-2008
You can redirect the program's output to a file. This file will has the output you need. At last, you can remove this temporary file by calling the remove() command, ex: remove(file); where file is a char * containing the file's name.
For example:
system(ls -l > temp);
//code ... you can use temp t see the output ...
remove(temp);
# 5  
Old 05-27-2008
But sometimes I need to load a shared object and call the function.
In that case the function will be opened and prints messages (log messages) on the terminal.

Loading shared library using dlopen(),locating the function in so using dlsym and executing the function.
Here is the problem.

int (*abc)(int , int)
handle=dlopen("shareobject.so", RTLD_NOW);
abc =dlsym(handle,"fw");

//Executing function "fw" like
(*abc)(x,y)


In this case I need to capture the output only from the last statement.
# 6  
Old 05-28-2008
got it

#include <stdio.h>

main()
{
int fd;
fpos_t pos;
printf("First Line\n");

fflush(stdout);
fgetpos(stdout, &pos);
fd = dup(fileno(stdout));
freopen("stdout.out", "w", stdout);

system("ls -l");

fflush(stdout);
dup2(fd, fileno(stdout));
close(fd);
clearerr(stdout);
fsetpos(stdout, &pos);

printf("Last line again to stdout\n");
}
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. Shell Programming and Scripting

Urgent !!

Hello All, I want to use scp for copying multiple files ( files locations are stored in an array ) from remote server from different locations without prompting password every time . I will supply password once and it should be able to copy every file mentioned in an array. eg :- array have ... (1 Reply)
Discussion started by: manpav
1 Replies

3. Shell Programming and Scripting

Need urgent help

Hi geeks, I'm trying to write a below script, but it throws an error, please check and correct me. #!/bin/bash #The below script will extract the string error1 error2 and error3 and also it will count and list the occurrence count1='grep -i "error1" test.txt | wc -l' count2='grep -i "error2"... (4 Replies)
Discussion started by: naren nandale
4 Replies

4. Shell Programming and Scripting

Need Urgent help

Hi friends, I need urgent help here: Issue: I need to create shell script that will find the files & throw an error through job (autosys) when file not found. Daily we use to receive 3 files from a system. Obstacles: 1) All 3 files names are same. 2) Timestamp is same. 3)... (1 Reply)
Discussion started by: tush
1 Replies

5. Shell Programming and Scripting

Urgent!!

Hi I have a file containing DE 3'UTR in Homo sapiens alpha-1-B glycoprotein (A1BG), mRNA. SQ Sequence 216 BP; 37 A; 58 C; 69 G; 52 T; 0 other; DE 3'UTR in Homo sapiens alpha-1-B glycoprotein (A1BG), mRNA. SQ Sequence 1844 BP; 358 A; 483 C; 434 G; 569 T; 0 other; DE 3'UTR in Homo... (1 Reply)
Discussion started by: jyotirmoy21
1 Replies

6. Red Hat

urgent

abb 117.96.113.21 cgg 101.2.104.42 cgg 110.227.247.236 desk 203.20.35.28 png 1.39.242.241 png 1.39.242.241 rzx 101.2.104.42 rzx 115.246.160.36 abb 49.138.242.187 how to find the count of this file wtrto ip thnx in advance (4 Replies)
Discussion started by: himanshu1.singh
4 Replies

7. UNIX for Advanced & Expert Users

need help urgent...........

Hi friends.. I am using the below command to search few files from many folders which is under one folder.. i mean let say the path is A/B/C...and inside C...i have 1-10 folder... the below command is working fine.... for i in 1 3 5 7; do find /A/B/C/${i} -name "*.txt" -o -name "*.csv"... (3 Replies)
Discussion started by: sapan123
3 Replies

8. UNIX for Advanced & Expert Users

URGENT,URGENT- Need help tape drive installation

Hi, I am trying to attach tape drive to sun V890 running Solaris 9 on it. I have installed HBA(qlogic) in slot 1 of 0-8 slots and booted the system. I do not see HBAin prtdiag output. The tape drive is not attached to HBA. The tape drive I am going to attach is Sony AIT3. 1.How can I make... (3 Replies)
Discussion started by: sriny
3 Replies

9. Solaris

Need Help Urgent

Hi. My E250 server (Solaris 8) running oracle database gets hangup in between. I checked the logs in /var/adm/messages but could not find anything related to this. can anyone help me out? bala (3 Replies)
Discussion started by: balaji_prk
3 Replies
Login or Register to Ask a Question