02-05-2002
You also might want to look at "man system" and "man popen".
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Say in unix (AIX) m/c, I am logged in with s1 user and want to start process p1 with user credentials of s2.
I can do manually in this way:
#su - s2
#enter password for s2> somePassword
$ p1
But all this I have to do through a java program. How to pass the password through program.
One... (1 Reply)
Discussion started by: shailendrat
1 Replies
2. Programming
Hi all,
I tried writing an .ec program connecting to informix database
from solaris platform Sun 5.7
informix version that i had to used when i compiled the program was 9.21.UC3
the binary when i ported solaris box with informix version 9.40.UC5 i am unable to run that
i am encountering... (0 Replies)
Discussion started by: matrixmadhan
0 Replies
3. Programming
Hi ,
I m actually trying to implement pipes program,but after executing the execvp(),my program is getting hanged up :mad:
Actaully i m getting the desired output expected from execvp()...but once results are displayed on the output screen ,program is getting hanged up
values of... (3 Replies)
Discussion started by: Crab
3 Replies
4. Programming
I wrote a code like this.......
#include <iostream>
#include <stdio.h>
#include <mysql.h>
#include <string.h>
#include <stdlib.h>
using namespace std;
#include "Connection.h"
int main()
{
char *Host = (char *)"localhost";
char *Database =(char *)"sachin";
char... (3 Replies)
Discussion started by: ps_sach
3 Replies
5. Solaris
hey everybody,
i am currently working on solaris 10 os on a m5000 server. my problem is when i want the exact size of a program in execution, i am unable to do it. earlier i thought the RSS field of prstat but because of its large size it cant be the size. pmap -x shows some output but it includes... (2 Replies)
Discussion started by: aryansheikh
2 Replies
6. Shell Programming and Scripting
I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies
7. Shell Programming and Scripting
Hello,
Please help me out to execute this perl program:
#!/usr/bin/perl -w
use strict;
use Win32::OLE qw(in with);
use Win32::OLE::Const 'Microsoft Excel';
$Win32::OLE::Warn = 3; # die on errors...
# get already active Excel application or open new
my... (6 Replies)
Discussion started by: suvenduperl
6 Replies
8. UNIX for Dummies Questions & Answers
What system calls or commands do I need to use in order to execute a different program from an already running process? (1 Reply)
Discussion started by: justOne21
1 Replies
9. Shell Programming and Scripting
Overview:
I have an AWK program that parses thru a database backup
server log file and outputs ths following parameters
SRNO DATE : TIME SIZE IN(KB) DATABASE NAME DUMP TYPE
1 May 16 2012: 13:30:00 6874 TestDB database
2 May 16 2012: 13:30:44 11462 master database
Problem:
This program has... (5 Replies)
Discussion started by: JolietJake
5 Replies
10. Programming
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
POPEN(3) Linux Programmer's Manual POPEN(3)
NAME
popen, pclose - pipe stream to or from a process
SYNOPSIS
#include <stdio.h>
FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
popen(), pclose():
_POSIX_C_SOURCE >= 2 || _XOPEN_SOURCE || _BSD_SOURCE || _SVID_SOURCE
DESCRIPTION
The popen() function opens a process by creating a pipe, forking, and invoking the shell. Since a pipe is by definition unidirectional,
the type argument may specify only reading or writing, not both; the resulting stream is correspondingly read-only or write-only.
The command argument is a pointer to a null-terminated string containing a shell command line. This command is passed to /bin/sh using the
-c flag; interpretation, if any, is performed by the shell. The type argument is a pointer to a null-terminated string which must contain
either the letter 'r' for reading or the letter 'w' for writing. Since glibc 2.9, this argument can additionally include the letter 'e',
which causes the close-on-exec flag (FD_CLOEXEC) to be set on the underlying file descriptor; see the description of the O_CLOEXEC flag in
open(2) for reasons why this may be useful.
The return value from popen() is a normal standard I/O stream in all respects save that it must be closed with pclose() rather than
fclose(3). Writing to such a stream writes to the standard input of the command; the command's standard output is the same as that of the
process that called popen(), unless this is altered by the command itself. Conversely, reading from a "popened" stream reads the command's
standard output, and the command's standard input is the same as that of the process that called popen().
Note that output popen() streams are fully buffered by default.
The pclose() function waits for the associated process to terminate and returns the exit status of the command as returned by wait4(2).
RETURN VALUE
The popen() function returns NULL if the fork(2) or pipe(2) calls fail, or if it cannot allocate memory.
The pclose() function returns -1 if wait4(2) returns an error, or some other error is detected. In the event of an error, these functions
set errnro to indicate the cause of the error.
ERRORS
The popen() function does not set errno if memory allocation fails. If the underlying fork(2) or pipe(2) fails, errno is set appropri-
ately. If the type argument is invalid, and this condition is detected, errno is set to EINVAL.
If pclose() cannot obtain the child status, errno is set to ECHILD.
CONFORMING TO
POSIX.1-2001.
The 'e' value for type is a Linux extension.
BUGS
Since the standard input of a command opened for reading shares its seek offset with the process that called popen(), if the original
process has done a buffered read, the command's input position may not be as expected. Similarly, the output from a command opened for
writing may become intermingled with that of the original process. The latter can be avoided by calling fflush(3) before popen().
Failure to execute the shell is indistinguishable from the shell's failure to execute command, or an immediate exit of the command. The
only hint is an exit status of 127.
SEE ALSO
sh(1), fork(2), pipe(2), wait4(2), fclose(3), fflush(3), fopen(3), stdio(3), system(3)
COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU
2013-04-19 POPEN(3)