10-24-2013
For a more general response to your question, consult the man page for popen(3) and note how a pipe is used for communication (which is absent from system(3)).
Within python, instead of os.system, refer to the subprocess module or os.popen.
Regards,
Alister
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I am a newbie and would like some help with the following -
Trying to search fileA for a string similar to -
AS11000022010 30.4 31.7 43.7 53.8 60.5 71.1 75.2 74.7 66.9 56.6 42.7 32.5 53.3
I then want to replace that string with a string from fileB - ... (5 Replies)
Discussion started by: ncwxpanther
5 Replies
2. Shell Programming and Scripting
Hi ,
I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code.
my $current_value=12345;
my @users=("bob","ben","tom","harry");
open DBLIST,"<","/var/tmp/DBinfo";
my @input = <DBLIST>;
foreach (@users)
{
my... (11 Replies)
Discussion started by: chidori
11 Replies
3. Shell Programming and Scripting
I need to compare the output files in a directory for sftp, looking through a mask.
Return the full file name.
Eg.
I have a file named locally:
test.txt
I must check through sftp, if a file with the following name:
test_F060514_H173148.TXT
My idea is for the filename to a... (0 Replies)
Discussion started by: Jomeaide
0 Replies
4. Shell Programming and Scripting
I have two files:
file 1:
hello.com neo.com,japan.com,example.com
news.net xyz.com, telecom.net, highlands.net, software.com
example2.com earth.net, abc.gov.uk
file 2:
neo.com
example.com
abc.gov.uk
file 2 are the search keys to search in file 1 if any of the search... (7 Replies)
Discussion started by: csim_mohan
7 Replies
5. UNIX for Dummies Questions & Answers
I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies
6. Shell Programming and Scripting
Hi guys,
I have a text file named file1.txt that is formatted like this:
001 , ID , 20000
002 , Name , Brandon
003 , Phone_Number , 616-234-1999
004 , SSNumber , 234-23-234
005 , Model , Toyota
007 , Engine ,V8
008 , GPS , OFF
and I have file2.txt formatted like this:
... (2 Replies)
Discussion started by: An0mander
2 Replies
7. Shell Programming and Scripting
Hello all,
I have a verilog file as following (part of it):
old.v:
bw_r_rf16x32 AUTO_TEMPLATE (
1957 // .rst_tri_en (mem_write_disable),
1958 .rclk (clk),
1959 .bit_wen (dva_bit_wr_en_e),
1960 .din ... (5 Replies)
Discussion started by: Zam_1234
5 Replies
8. Programming
I am having trouble understanding why these two commands differ with one producing the desire results and the other not. An example:
capture_str = 'xserver-xorg-video-qxl-dbg (0.1.1-2+b2 , 0.1.1-2+b1 , 0.1.1-2 ) X.Org X server -- QXL display driver (debugging symbols)'
re.search(r'(?<=\\, ).*',... (2 Replies)
Discussion started by: metallica1973
2 Replies
9. Programming
I have a list as follows:
From this i need to grep the element using keyword as "primary" and return output as
12:13-internet-wifi-primary
i used as follows
if (i <= (len(system_info))):
ss = system_info
print... (5 Replies)
Discussion started by: Priya Amaresh
5 Replies
LEARN ABOUT FREEBSD
pclose
POPEN(3) BSD Library Functions Manual POPEN(3)
NAME
popen, pclose -- process I/O
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdio.h>
FILE *
popen(const char *command, const char *type);
int
pclose(FILE *stream);
DESCRIPTION
The popen() function ``opens'' a process by creating a bidirectional pipe forking, and invoking the shell. Any streams opened by previous
popen() calls in the parent process are closed in the new child process. Historically, popen() was implemented with a unidirectional pipe;
hence many implementations of popen() only allow the type argument to specify reading or writing, not both. Since popen() is now implemented
using a bidirectional pipe, the type argument may request a bidirectional data flow. The type argument is a pointer to a null-terminated
string which must be 'r' for reading, 'w' for writing, or 'r+' for reading and writing.
A letter 'e' may be appended to that to request that the underlying file descriptor be set close-on-exec.
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 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().
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 VALUES
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 stream is not associated with a ``popened'' command, if stream already ``pclosed'', or if wait4(2)
returns an error.
ERRORS
The popen() function does not reliably set errno.
SEE ALSO
sh(1), fork(2), pipe(2), wait4(2), fclose(3), fflush(3), fopen(3), stdio(3), system(3)
HISTORY
A popen() and a pclose() function appeared in Version 7 AT&T UNIX.
Bidirectional functionality was added in FreeBSD 2.2.6.
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.
The popen() function always calls sh(1), never calls csh(1).
BSD
May 20, 2013 BSD