LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-07-2003, 06:44 PM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Bug in c code calling bash code


Bug in c code calling bash code

ERROR: value too long for type character varying(16)
Bad script

=====================================
Code:
#include <stdio.h>      
#include <stdlib.h>        
#include <string.h> 

start_processes()
{
  FILE *f, *fopen();
  f = popen ("/usr/suid/webofc/getdata | suid-to webofc "
                    "ssh `grep \"^10.0.0.1\" /etc/hosts | head -n 1 "
                    "| awk '{print $4}'` -C suid putdata update && "
                    "suid updatefirewall && suid " 
                    " updatemirrorhosts ", "w");
}

/****************************************/
main()
{
   start_processes();
}

Last edited by Linh; 08-08-2003 at 10:20 AM.
 
Old 08-08-2003, 03:27 AM   #2
DIYLinux
Member
 
Registered: Jul 2003
Location: NL
Distribution: My own
Posts: 92

Rep: Reputation: 18
Make a separate script containing the commands you want to run. Use popen to call this script.
 
Old 08-08-2003, 08:16 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: Bug in c code calling bash code

The line:
Code:
" updatemirrorhosts ", "w"); " */
Should be:
Code:
" updatemirrorhosts ", "w");
 
Old 08-08-2003, 08:23 AM   #4
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Please oh please tell me this is not the whole C program.
 
Old 08-08-2003, 10:22 AM   #5
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
To Hko

To Hko

I did fixed as you have suggested, but the error is still there.
 
Old 08-08-2003, 11:44 AM   #6
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Seriously, if this is the whole program, don't do it this way .. just do it in a bash script. There's nothing but trouble to be gained from making a C program out of this.
 
Old 08-10-2003, 05:36 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I think the error comes from the (shell) command you execute. Not from the C-code. It compiles fine, right?

Can't verify that though, because I don't have the commandline utils "getdata", "suid-to", etc. installed, and I have no idea what they should.

Try to execute the same line from whitin a shell, and find out wich program is causing the errors.
 
Old 08-10-2003, 06:20 AM   #8
Tarts
Member
 
Registered: Feb 2003
Distribution: Slackware 9.1 (exclusively) ;)
Posts: 344

Rep: Reputation: 30
Re: Bug in c code calling bash code

Quote:
Originally posted by Linh
Bug in c code calling bash code

ERROR: value too long for type character varying(16)
Bad script

=====================================
Code:
#include <stdio.h>      
#include <stdlib.h>        
#include <string.h>//we don't need this right now, and shouldn't you 
                                  //you use 'strings.h instead?
void start_processes()
{
  FILE *f, *fopen();
  f = popen ("/usr/suid/webofc/getdata | suid-to webofc "
                    "ssh `grep \"^10.0.0.1\" /etc/hosts | head -n 1 "
                    "| awk '{print $4}'` -C suid putdata update && "
                    "suid updatefirewall && suid " 
                    " updatemirrorhosts ", "w");
}

/****************************************/
int main()
{
   start_processes();
   return 0;
}
I would make these modification's if it where me.
Someone correct me if i'm wrong i don't usually critiqe other's code, i'm just waiting for a reply to my thread.

Last edited by Tarts; 08-10-2003 at 06:25 AM.
 
Old 08-10-2003, 03:49 PM   #9
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Quote:
Originally posted by Strike
Seriously, if this is the whole program, don't do it this way .. just do it in a bash script. There's nothing but trouble to be gained from making a C program out of this.
Seriously, this is getting ridiculous. This is NOT SOMETHING THAT SHOULD BE DONE IN A C PROGRAM.
 
Old 08-10-2003, 04:10 PM   #10
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
Quote:
by Strike
Seriously, this is getting ridiculous. This is NOT SOMETHING THAT SHOULD BE DONE IN A C PROGRAM.
i said that to Linh in the third or fourth thread he posted, its nice to see now were on thread approx 25 someone else is noticing this.
 
Old 08-11-2003, 05:30 PM   #11
Linh
Member
 
Registered: Apr 2003
Posts: 178

Original Poster
Rep: Reputation: 30
Smile Reply

OK, Lady and gentlemen, I won 't asked about it again.
Thank you all for your help.
 
Old 08-12-2003, 04:27 AM   #12
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
tho it should not worthy of being a C program, it still makes for an example of how to use popen(). Hell, its my 1st time seeing the function.

doing a man popen now.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
User Preferences: Use HTML code instead of vB code? (vB code is overrated) stefanlasiewski LQ Suggestions & Feedback 5 07-26-2005 01:37 AM
calling external applications in your c++ code drisay Programming 2 01-25-2005 12:41 PM
Bug in C code Linh Programming 3 07-07-2003 06:06 PM
Calling long BASH code within a C program Linh Programming 4 06-24-2003 01:41 PM
C program code calling a Linux system command Linh Programming 1 06-05-2003 01:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration