The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > OS Specific Forums > SUN Solaris
Google UNIX.COM


SUN Solaris The Solaris Operating System, usually known simply as Solaris, is a free Unix-based operating system introduced by Sun Microsystems .

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 12-13-2004
Registered User
 

Join Date: Nov 2004
Location: India, Bangalore
Posts: 18
Question popen truncates the command line passed to it

********************************
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.
Reply With Quote
Forum Sponsor
  #2  
Old 12-13-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
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?
Reply With Quote
  #3  
Old 12-14-2004
Registered User
 

Join Date: Nov 2004
Location: India, Bangalore
Posts: 18
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.
Reply With Quote
  #4  
Old 12-14-2004
Registered User
 

Join Date: Nov 2004
Location: India, Bangalore
Posts: 18
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.
Reply With Quote
  #5  
Old 12-16-2004
Registered User
 

Join Date: Nov 2004
Location: India, Bangalore
Posts: 18
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.
Reply With Quote
  #6  
Old 12-22-2004
Registered User
 

Join Date: Nov 2004
Location: India, Bangalore
Posts: 18
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.
Reply With Quote
  #7  
Old 12-23-2004
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
Re: popen throws 'bad file number' error

Quote:
Originally posted by diganta
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?
You have bugs in your code. Buggy code often works differently on different platforms
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:04 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0