LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bug in c code calling bash code (https://www.linuxquestions.org/questions/programming-9/bug-in-c-code-calling-bash-code-79979/)

Linh 08-07-2003 06:44 PM

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();
}


DIYLinux 08-08-2003 03:27 AM

Make a separate script containing the commands you want to run. Use popen to call this script.

Hko 08-08-2003 08:16 AM

Re: Bug in c code calling bash code
 
The line:
Code:

" updatemirrorhosts ", "w"); " */
Should be:
Code:

" updatemirrorhosts ", "w");

Strike 08-08-2003 08:23 AM

Please oh please tell me this is not the whole C program.

Linh 08-08-2003 10:22 AM

To Hko
 
To Hko

I did fixed as you have suggested, but the error is still there.

Strike 08-08-2003 11:44 AM

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.

Hko 08-10-2003 05:36 AM

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.

Tarts 08-10-2003 06:20 AM

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.

Strike 08-10-2003 03:49 PM

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.

kev82 08-10-2003 04:10 PM

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.

Linh 08-11-2003 05:30 PM

Reply
 
OK, Lady and gentlemen, I won 't asked about it again.
Thank you all for your help.

Robert0380 08-12-2003 04:27 AM

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.


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