Thread: System Command Use

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    17

    Smile System Command Use

    Hello friends:

    I am a new Linux C programmer and i`m not sure how to use the "system" command in a C script. For example: I am usign the rrdtool program to create some graphics and I have to write the next command at shell prompt.

    "rrdtool update test.rrd 920804700:12345" ok?
    now, i want to use this sentence in a C script, then i write:

    system("rrdtool update test.rrd 920804700:12345")

    the "920804700" and "12345" numbers are stored in a file and I already know how to retrieve them and assign to the char variables "a" and "b". I want to know how can i relate these numbers with the system command?

    i`m thinking of something like this:
    system("rrdtool update test.rrd "%s",":"%s" , a , b) ... is this right?

    Can anyone help me out?
    Thanks!!!!

    A Man can be whatever he wants to
    be

  2. #2
    Registered User Sake's Avatar
    Join Date
    Jan 2005
    Posts
    89
    >>i`m thinking of something like this
    Close, but system doesn't work like printf. You need to build a string with sprintf, or better yet, snprintf if you have it, then pass that string to system.
    Code:
    char command[BUFSIZ];
    
    ...
    
    sprintf(command, "rrdtool update test.rrd %s: %s", a, b);
    system(command);
    Or, since a and b are also strings, you could use strcat and friends if you want.
    Kampai!

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    17

    Talking

    Thanks a lot Sake!!!
    I`ll try that
    A Man can be whatever he wants to
    be

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Operating System
    By Houssen in forum C Programming
    Replies: 18
    Last Post: 04-22-2008, 12:51 PM
  2. File System Implementation
    By dodgeviper in forum C Programming
    Replies: 9
    Last Post: 11-16-2007, 01:04 PM
  3. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  4. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM