Sponsored Content
Top Forums UNIX for Advanced & Expert Users ftp application behaving erratically Post 59752 by diganta on Thursday 30th of December 2004 12:49:09 AM
Old 12-30-2004
Agreed that popen cannot modify "line". But somehow that is what is happening. We cannot use printf here as the application is running as a deamon. I have called a function just before and after popen that will do the task of printf but it will write to a file. The code snippet is like,

...
...
gen_log("Value of line is %s", line); //10
popen (line, "r"); //11
gen_log("Value of line is %s", line); //12
....
....

At line 10 the value of line is "/bin/ls -l *temp" (lets assume we passed *temp as the argument to ls).
At line 12 the value of line is "/bin/ls". The rest gets truncated. Again if we hard code the value of line, the application just crashes.
 

10 More Discussions You Might Find Interesting

1. Programming

ftp application using socket programming

i have made a ftp application in socket programming which uses TCP/IP .. i have the problem runing the only problem is on the client side i take the user input for the file to be downloaded from the command promt. write(s, argv, strlen(argv)+1); // this is how i write in client side argv is... (1 Reply)
Discussion started by: toughguy2handle
1 Replies

2. UNIX for Advanced & Expert Users

csplit not behaving

I have a large file with the first 2 characters of each line determining the type of record. type 03 being a subheader and then it will have multiple 04 records. eg: 03,xxx,xxxx,xxxx 04,xxxxxxxxxxxxxxxxxxxxxxxxxxxx 04,xxxxxxxxxxxxxxxxxxxxxxxxxxxx 03,xxx,xxx,xxx ... (2 Replies)
Discussion started by: badg3r
2 Replies

3. Shell Programming and Scripting

tr command behaving unexpectedly

Im trying to execute the below command on our server to list files and replace the newline in the file list with spaces, but the character 'n' is getting replaced with a space, is there any environment variable that needs to be set in UNIX? sh -c 'ls -trx... (1 Reply)
Discussion started by: rameshrr3
1 Replies

4. UNIX for Advanced & Expert Users

FTP behaving erraneous way

Hi Gurus, I tried FTP one file to UNIX which got values like wel^come If I see the content in unix, it shows like wel^Zcome ^ coverted into ^Z (Control + Z ) Can someone please share what is happening here? Thanks, Shahnaz (5 Replies)
Discussion started by: shahnazurs
5 Replies

5. UNIX and Linux Applications

Firefox35 displays pngs erratically

I have been using firefox3.5 now for some months and noticed that some images, notably in the png format, do not display correctly: the images are not displayed at all or display in part whereby the rest of the image shows a black rectangle. Does anybody else suffer from this problem? Desktop:... (0 Replies)
Discussion started by: figaro
0 Replies

6. Red Hat

nslookup behaving strangely

I have two servers on same domain. one can nslookup other cannot Psu100 can lookup to psu000, psu010 & psu011 Psu110 can NOT lookup to psu000, psu010 & psu011 I verified resolv.conf entries on both psu000 and psu010 and it contains both name servers (10.200.10.21 & 10.200.11.22).I am... (1 Reply)
Discussion started by: scorohan
1 Replies

7. Programming

Application behaving in 3 different ways on 3 different machines

Hello. During the holidays I've been developing an application on my desktop computer at home. I setup a repository on github, so when I got back to work I cloned the repo to my laptop. It wouldn't work. The app is comprised of a client and a server, strangely enough the server would segfault... (10 Replies)
Discussion started by: erupter
10 Replies

8. Shell Programming and Scripting

awk not behaving as expected

Hi, Immediate help on below will be appreciated. I have to read a file (max of 10MB) which will have no new line characters, i.e. data in single line. and have to inster '\n' at every 100 characters. and if record starts with 'BUCA' then need to pick value of length 10 at position 71 and... (7 Replies)
Discussion started by: maks475
7 Replies

9. UNIX for Advanced & Expert Users

[Solved] wc behaving weirdly

Can anyone explain why wc is behaving weirdly? Their are only 2 occurrences but wc thinks their are 7 occurrences. I have even manually checked this. $ grep -i base * lit: base xx lit.lst:003- 00103 BASE XX $ grep -i base * | wc -w ... (2 Replies)
Discussion started by: cokedude
2 Replies

10. Shell Programming and Scripting

Read command acting erratically

I have been trying to use read in a script with issues so I tried some things on the command line. $ echo "testing 123" | read x ; echo $xand $ echo "testing 123" | read -r x ; echo $xare only producing any output after being invoked the first time after rebooting the machine. I also got into... (14 Replies)
Discussion started by: Michael Stora
14 Replies
POPEN(3)						   BSD Library Functions Manual 						  POPEN(3)

NAME
pclose, popen -- process I/O LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdio.h> FILE * popen(const char *command, const char *mode); 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 mode argument to specify reading or writing, not both. Because popen() is now imple- mented using a bidirectional pipe, the mode argument may request a bidirectional data flow. The mode argument is a pointer to a null-termi- nated string which must be 'r' for reading, 'w' for writing, or 'r+' for reading and writing. 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; it 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) 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). HISTORY
A popen() and a pclose() function appeared in Version 7 AT&T UNIX. Bidirectional functionality was added in FreeBSD 2.2.6. BSD
May 3, 1995 BSD
All times are GMT -4. The time now is 12:20 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy