12-17-2004
serious problem with popen
The problem is not supposed to be with popen. popen is a standard function and I do not think that it will modify the value of "line". It must be getting modified somewhere else somehow. The value of line is perfect just before popen. Just after popen it is changed. Any idea how i can find how it is getting changed?
Also, the behaviour of the application is strange. Sometimes the client - server link gets disconnected after the first 'ls' when we try another 'ls'. Sometimes it happens only after we give a 'cd' command followed by a 'ls' command.
If anyone can help me, I'll be hightly obliged.
8 More Discussions You Might Find Interesting
1. Programming
Hi,
Can someone help me to figure out whether this code is to write file to /tmp/TIMECLOCK directory or just to asign a variable with "/tmp/TIMECLOCK/name.log_copy.pid" as the string?
I am looking into an old C program and could not figure out where in the code that creates... (1 Reply)
Discussion started by: whatisthis
1 Replies
2. Programming
Hi All,
I was reading the man page of snprintf function and it saids that snprintf adds a null terminator at the end of the string, but I remember once someone told me that snprintf doesn't guarantee the insertion of a null terminator character.
What do you think? Does anyone have experience... (4 Replies)
Discussion started by: lagigliaivan
4 Replies
3. Programming
Hi
My requirement is to convert the following to C++
char buffer;
sprintf(buffer,"%s %-50s %6s %-6d %s\n",a.substr(0,5),a.substr(10,20))
Since the buffer is of varying length, i cannot hardcode the value as 90.
i would like to convert the buffer to string object so that it can receive any... (1 Reply)
Discussion started by: dhanamurthy
1 Replies
4. Shell Programming and Scripting
Dear all,
I am new to perl script and would need some help for my 1st script. I wrote a script to search sprintf(buf,"%s", sourcestring) and replace with snprintf(buf, sizeof(buf),"%s", sourcestring). As snprintf() requires an extra argument, so it is not a simple search-and-replace. I need to... (1 Reply)
Discussion started by: ChaMeN
1 Replies
5. Shell Programming and Scripting
Hi,
anyone knows the perl search-and-replace expression for
strcpy (char * destination, const char * source ); to
strncpy ( char * destination, const char * source, size_t num ); ?
the first and second arguments are the same (destination and source), the difference being that strncpy... (1 Reply)
Discussion started by: ChaMeN
1 Replies
6. Programming
Hi,
I am trying to migrate an application from Solaris to AIX 5.3.1. In both platforms the locale settings are as follows:
Result of executing "locale"
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
In solaris when you execute this... (5 Replies)
Discussion started by: coldas57
5 Replies
7. Shell Programming and Scripting
Hi
I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it
The code is that:
{
if (NF==17){
print $0
}else{
fields=NF;
all=$0;
while... (2 Replies)
Discussion started by: fate
2 Replies
8. Programming
Hi,
I have the below sample code to hash the input number read from file. File will have 16 to 19 digit number and executable hash the number using some logic and returns the hashed value. Each digit in the 16 digit number is converted to a 4 byte value. That if the input is 16digit integer, the... (6 Replies)
Discussion started by: ramkrix
6 Replies
popen(3) Library Functions Manual popen(3)
NAME
popen - Initiates a pipe to a process
LIBRARY
Standard C Library (libc.so, libc.a)
SYNOPSIS
#include <stdio.h>
FILE *popen (
const char *command,
const char *type );
STANDARDS
Interfaces documented on this reference page conform to industry standards as follows:
popen(): XPG4, XPG4-UNIX
Refer to the standards(5) reference page for more information about industry standards and associated tags.
PARAMETERS
Points to a null-terminated string containing a shell command line. Points to a null-terminated string containing an I/O mode.
DESCRIPTION
The popen() function creates a pipe between the calling program and a shell command to be executed. It returns a pointer to a FILE struc-
ture for the stream.
If the type parameter is the value r, the calling program can read from the standard output of the command by reading from the returned
file stream. If the type parameter is the value w, the calling program can write to the standard input of the command by writing to the
returned file stream.
Because open files are shared, a type r command can be used as an input filter and a type w command as an output filter.
NOTES
Programs using the popen() function to invoke an output filter should beware of possible deadlock caused by output data remaining in the
program's buffer. This can be avoided by either using the setbuf() function to ensure that the output stream is unbuffered, or by using
the fflush() function to ensure that all buffered data is flushed before calling the pclose() function. If the original processes and the
process started with the popen() function concurrently read or write a common file, neither should use buffered I/O. If they do, the
results are unpredictable.
RETURN VALUES
Upon successful completion, the popen() function returns a pointer to the FILE structure for the opened stream. In case of error because
files or processes could not be created, the popen() function returns a null pointer.
RELATED INFORMATION
Functions: exec(2), fork(2), fclose(3), fopen(3), pclose(3), pipe(2), setbuf(3)
Standards: standards(5) delim off
popen(3)