05-04-2010
Read the man page for system(). It does not return a string, it returns the status of the command, as an integer -- probably 0 most of the time, or nonzero on error. If you want to actually capture the output of the command, use popen, it opens a FILE stream you can read from.
Better yet, don't create external processes for things you can do inside C. See man gettimeofday and man ctime.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I am presently stuck in a csv file.
INPUT CSV
baseball,NULL,8798765,Most played
baseball,NULL,8928192,Most played
baseball,NULL,5678945,Most played
cricket,NOTNULL,125782,Usually played
cricket,NOTNULL,678921,Usually played
EXPECTED OUTPUT CSV
... (7 Replies)
Discussion started by: scripter12
7 Replies
2. Shell Programming and Scripting
Hi,
I have a comma (,) delimited file, in which few fields are enclosed with in double quotes " ". I have to print the records in the file which donot have expected number of field with the line number.
File1
====
name,desgnation,doj,project #header#... (7 Replies)
Discussion started by: machomaddy
7 Replies
3. Shell Programming and Scripting
Hi All,
I am in middle of one script. I want output in the form of xls file.
There are 4 fields - user name, email Id, full name, date of birth. I want these details to get in seperate columns.
But, i am getting it in the single cell and as like a paragraph.:mad:
Please suggest me some... (8 Replies)
Discussion started by: Agupte
8 Replies
4. Shell Programming and Scripting
Hi
I have written below script to get the data in table form.
#!/bin/sh
echo "File Name\tType"
for i in *;
do
echo "$i\t\c"
if ; then
echo "directory"
elif ; then
echo "symbolic link"
elif ; then
echo "file"
else
echo "unknown"
fi
donehowever i am getting output in different way... (3 Replies)
Discussion started by: scriptor
3 Replies
5. Shell Programming and Scripting
lyang001@lyang001-OptiPlex-9010:~$ service --status-all |grep dbus
acpid
acpi-support
alsa-restore
alsa-store
anacron
apport
atd
avahi-daemon
bluetooth
cgroup-lite
console-setup
cron
cups
dbus
dmesg
dns-clean
failsafe-x
... (1 Reply)
Discussion started by: yanglei_fage
1 Replies
6. Shell Programming and Scripting
How to capture system() function output in awk variable and the print that awk variable..... (8 Replies)
Discussion started by: bharat1211
8 Replies
7. Shell Programming and Scripting
Good Moring,
I am currently reading about awk in a manual and following the examples using the oratab file.
My system is SOLARIS 10
I think I am getting strange behavior judging by what the book says to do and what I am getting with my little program.
Here is my program:
grep -v oratab |... (4 Replies)
Discussion started by: bdby
4 Replies
8. Shell Programming and Scripting
#cat /tmp/input
old_array old_dev new_dev new_array
0577 008AB 01744 0125
0577 008AC 01745 0125
0577 008AD 005C8 0125
0577 008AE 005C9 0125
0577 008AF 005CA 0125
0577 008B0 005CB 0125
0577 008B1 005CC 0125
cat test.sh
#!/bin/ksh... (4 Replies)
Discussion started by: mbak
4 Replies
9. Shell Programming and Scripting
Hello,
I am practising awk and decided to compare two columns and print the result of the comparison as third column
i/p data
c1,c2,c3
1,a,b
1,b,b
i am trying to compare the last two columns and if they match I am trying to print match else mismatch(Ideally i want that as a last column... (5 Replies)
Discussion started by: mkathi
5 Replies
LEARN ABOUT DEBIAN
pclose
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.
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.44 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
2010-02-03 POPEN(3)