![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems . |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| equivalent of sprintf in C++ | dhanamurthy | High Level Programming | 1 | 05-20-2008 06:18 PM |
| C99-snprintf 1.1 (Default branch) | iBot | Software Releases - RSS News | 0 | 01-20-2008 05:50 PM |
| C99-snprintf 1.0 (Default branch) | iBot | Software Releases - RSS News | 0 | 01-06-2008 02:50 PM |
| ksh scripting sprintf | gfhgfnhhn | Shell Programming and Scripting | 2 | 07-05-2006 05:11 AM |
| sprintf function | whatisthis | High Level Programming | 1 | 05-01-2006 01:58 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
********************************
Following is not the real issue. The issue is with popen. Plz continue forward with the thread to get a better picture. ******************************** Hi, I am working on a customised ftp application. In it we have used sprintf to store a UNIX command like "ls *test" to a temporary variable to execute it on the server and return the result to the client. However the sprintf and snprintf is not working properly. The following code segment will give an idea. -------------------------- char name[] = "*test"; char cmd[] = "/bin/ls -l %s"; char line[1024]; sprintf (line, cmd, name); --------------------------- After sprintf the expected result is, line = "/bin/ls -l *test" but what we are getting is, line = "/bin/ls" ---------------- Can anyone tell me what is wrong with the code? I will be highly indebted. Regards, Diganta Last edited by diganta; 12-14-2004 at 11:32 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
I cut and pasted your code and it works for me. You don't say how you displayed line. I added a line:
printf ("line = %s \n", line); Could you have a bug in your debugging statement? |
|
#3
|
|||
|
|||
|
the above code is working if I copy paste it and then compile it. However in my application there is one more line after the call to sprintf
name = line; the value are ok before this line. only after this line is the data getting truncated. Can you give me any idea why. Also, in the actual applycation the variable are like this, char line[1024]; //local variable of the function. char *cmd, *line: //passed as arguments to the function. |
|
#4
|
|||
|
|||
|
It seems I have found where the problem is. The problem is not with the assignment statement as stated above. It is in a call to popen. After calling popen as
fin = popen (line, "r"); the value of line gets truncated. Is there some issue with popen in Solaris? I have searched the man pages but could not find anything. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
popen throws 'bad file number' error
Sorry, I didn't get time to look into the real issue.
After putting some debugging logs I found that popen is throwing "Bad file number" error on the first call with "/bin/ls -l" as the argument. On the second call it throws "No child processes". (By throws I mean it sets the value at errno). Another strange behaviour is that after a put command the error thrown is "Illegal seek". I would like to point it out here that all these error are in Solaris only. The same application is being compiled for AIX also. There it is working just fine. Any idea why? Last edited by diganta; 12-22-2004 at 11:45 PM. |
|
#7
|
||||
|
||||
|
Re: popen throws 'bad file number' error
Quote:
|
||||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|