Sponsored Content
Full Discussion: little program error.
Top Forums Programming little program error. Post 302259633 by joey on Tuesday 18th of November 2008 02:24:08 PM
Old 11-18-2008
little program error.

I am trying to work this little program, its not working..

Code:
int main()

{
               FILE *fp;
               char *args[40];
               pid_t child, exited_pid;
               int status = 0;
               *args[0] = "less";
               fp = popen("ls", "r");
               child = fork();
               if(child == 0)
              {
                      dup2(fp->fd, 0);
                      if(execvp(args[0], args) == -1)
                             {
                                printf("error");
                               exit(EXIT_FAILURE);
                              }

                wait(&status);
                wait(&status);
}


I got error.
Warning: assignment makes integer from pointer without a cast
Error: 'FILE' has no member named 'fd'
Error: expected declaration or statement at end of input.


My whole goal of the program is to execute ls, and read from that program & store it in the buffer. Then my second program (argss[0]) reads the input coming from there and uses it...


help plzSmilie
 

10 More Discussions You Might Find Interesting

1. Programming

Error Compiling C program

Hi All, I tried to compile a C program but i am getting error while Linking . it says Undefined reference to ' ' (here it gives a method name which is defined Globally ). Can any body tell the resaon and remedy for the same . Iam stuck up here . Thanks (3 Replies)
Discussion started by: Vivek
3 Replies

2. AIX

Program Error

Hi, my IBM 9117-570 model (mounting SF230_126 firmware version) gives an errpt like the following. The problem is that no SRC code found at IBM information center web site. Some ideas where are those SRC searchable ? O.S. is AIX 5.2- tkx E18E984F 1119200506 P S SRC ... (0 Replies)
Discussion started by: Carmen123
0 Replies

3. Shell Programming and Scripting

Error in AWK Program

Hi Friends, I need your help. I am not able to execute one awk program .If you can solve the following small program then i can solve other one. $ vi prg #!/bin/awk -f BEGIN { # Print the squares from 1 to 10 the first way i=1; while (i <= 10) { ... (3 Replies)
Discussion started by: bikas_jena
3 Replies

4. Shell Programming and Scripting

Need help with program error

#!/bin/csh # # Time of day greeting # # usage: greet # if ($#argv == 0) then set hour = ‘date +%H’ else set hour = $argv endif # if ($hour < 12) then echo "Good Morning\!" else if ($hour < 18) then echo "Good Afternoon\!" ... (2 Replies)
Discussion started by: glock1800
2 Replies

5. Linux

an error in perl program

Hi I am having a file with 243 lines.. The file format s given below eg P25787 hsa03050 1 P20618 hsa03050 1 P25786 hsa03050 1 P49721 hsa03050 1 P54132 hsa03440 1 Q13472 hsa03470 1 Q05513 hsa04530 hsa04910 hsa04930 3 Q04759 ... (0 Replies)
Discussion started by: binnybio
0 Replies

6. Programming

Runtime error in C++ Program - Help

All, I am getting this when i try to ran a program in HP unix. Things i came across 1. i have a system HP-UNIX where this same exe is working. 2. We have set a new HP_UNIX with the same configration and copied the exe to the new system we are getting this error. 3. Only... (3 Replies)
Discussion started by: arunkumar_mca
3 Replies

7. Programming

An error in my c++ program... please help urgent.

The following is a program to convert an infix expression to postfix expression. //Convert an infix expression to postfix expression... #include<iostream> #include<string> #include<cstdlib> using namespace std; char ifx,pfx,stk; int top=-1,n; void push(char ch) { if(top!=n) ... (6 Replies)
Discussion started by: poonam.gaigole
6 Replies

8. Solaris

Shell program error!!!

Hello guys, This is an executable shell program that I want to execute, but it doesn't execute and gives error. The shell program that I want to execute is taken from a well-reputed book on Solaris 10. Here is the program #!/usr/bin/bash if test -a $1 then echo "Number of lines in file " $1... (2 Replies)
Discussion started by: gabam
2 Replies

9. Programming

Error in executing the C program

Hello Friends, I have written a code for the unisex bathroom which makes a policy that when a woman is in the bathroom only other women may enter, but not men, and vice versa. This program consists of four functions which a user defines but these functions are not properly working while... (4 Replies)
Discussion started by: Ravi Tej
4 Replies

10. Programming

Error in my FORTRAN program

I have a Fortran program and I am writing out to logical unit 7. The program is reading from a text file and writing to the new file formatted. It gets through the read and writes some to the file but then stops with the following error: 1525-013 The sequential WRITE statement cannot be... (5 Replies)
Discussion started by: KathyB148
5 Replies
popen(3C)						   Standard C Library Functions 						 popen(3C)

NAME
popen, pclose - initiate a pipe to or from a process SYNOPSIS
#include <stdio.h> FILE *popen(const char *command, const char *mode); int pclose(FILE *stream); DESCRIPTION
The popen() function creates a pipe between the calling program and the command to be executed. The arguments to popen() are pointers to null-terminated strings. The command argument consists of a shell command line. The mode argument is an I/O mode, either r for reading or w for writing. The value returned is a stream pointer such that one can write to the standard input of the command, if the I/O mode is w, by writing to the file stream (see Intro(3)); and one can read from the standard output of the command, if the I/O mode is r, by reading from the file stream. Because open files are shared, a type r command may be used as an input filter and a type w as an output filter. A trailing F character can also be included in the mode argument as described in fopen(3C) to enable extended FILE facility. The environment of the executed command will be as if a child process were created within the popen() call using fork(2). If the applica- tion is standard-conforming (see standards(5)), the child is created as if invoked with the call: execl("/usr/xpg4/bin/sh", "sh", "-c",command, (char *)0); otherwise, the child is created as if invoked with the call: execl("/usr/bin/sh", "sh", "-c",command, (char *)0); The pclose() function closes a stream opened by popen() by closing the pipe. It waits for the associated process to terminate and returns the termination status of the process running the command language interpreter. This is the value returned by waitpid(3C). See wait.h(3HEAD) for more information on termination status. If, however, a call to waitpid() with a pid argument equal to the process ID of the command line interpreter causes the termination status to be unavailable to pclose(), then pclose() returns -1 with errno set to ECHILD to report this condition. RETURN VALUES
Upon successful completion, popen() returns a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it returns a null pointer and may set errno to indicate the error. Upon successful completion, pclose() returns the termination status of the command language interpreter as returned by waitpid(). Other- wise, it returns -1 and sets errno to indicate the error. ERRORS
The pclose() function will fail if: ECHILD The status of the child process could not be obtained, as described in the DESCRIPTION. The popen() function may fail if: EMFILE There are currently FOPEN_MAX or STREAM_MAX streams open in the calling process. EINVAL The mode argument is invalid. The popen() function may also set errno values as described by fork(2) or pipe(2). USAGE
If the original and popen() processes concurrently read or write a common file, neither should use buffered I/O. Problems with an output filter may be forestalled by careful buffer flushing, for example, with fflush() (see fclose(3C)). A security hole exists through the IFS and PATH environment variables. Full pathnames should be used (or PATH reset) and IFS should be set to space and tab (" "). Even if the process has established a signal handler for SIGCHLD, it will be called when the command terminates. Even if another thread in the same process issues a wait(3C) call, it will interfere with the return value of pclose(). Even if the process's signal handler for SIGCHLD has been set to ignore the signal, there will be no effect on pclose(). EXAMPLES
Example 1 popen() example The following program will print on the standard output (see stdio(3C)) the names of files in the current directory with a .c suffix. #include <stdio.h> #include <stdlib.h> main() { char *cmd = "/usr/bin/ls *.c"; char buf[BUFSIZ]; FILE *ptr; if ((ptr = popen(cmd, "r")) != NULL) { while (fgets(buf, BUFSIZ, ptr) != NULL) (void) printf("%s", buf); (void) pclose(ptr); } return 0; } Example 2 system() replacement The following function can be used in a multithreaded process in place of the most common usage of the Unsafe system(3C) function: int my_system(const char *cmd) { FILE *p; if ((p = popen(cmd, "w")) == NULL) return (-1); return (pclose(p)); } ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |See below. | +-----------------------------+-----------------------------+ |MT-Level |Safe | +-----------------------------+-----------------------------+ The F character in the mode argument of popen() is Evolving. In all other respects this function is Standard. The pclose() function is Standard. SEE ALSO
ksh(1), pipe(2), fclose(3C), fopen(3C), posix_spawn(3C), stdio(3C), system(3C), wait(3C), waitpid(3C), wait.h(3HEAD), attributes(5), stan- dards(5) SunOS 5.11 14 Dec 2006 popen(3C)
All times are GMT -4. The time now is 07:09 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy