manipulating console output.

Discussion in 'C Programming' started by robannexs@gmail.com, Sep 19, 2006.

  1. Guest

    Hi all,

    I'm doing a small c program which backs up the mbr of hard disk.
    Currently working in linux.

    what i did was :
    system("sudo dd if=/dev/sda of=mbr.bin bs=512 count=1");

    This is the output i got from console.
    1+0 records in
    1+0 records out
    512 bytes (512 B) copied, 7.6e-05 seconds, 6.7 MB/s

    is there anyway I can don't print these messages? or capture them and
    do some parsing such that i will be able to print my own messages?

    Thanks and best regards,
    Jackson
    , Sep 19, 2006
    #1
    1. Advertising


  2. > what i did was :
    > system("sudo dd if=/dev/sda of=mbr.bin bs=512 count=1");
    >

    Because the standard implementation of system() is to issue the command
    to a shell, you should try output redirection of stdout and stderr,
    like so:

    system("sudo dd if=/dev/sda of=mbr.bin bs=512 count=1 2>&1
    1>>/var/myprog/log");

    The 2>&1 means redirect stderr to stdout, and 1>>... means append
    stdout to specified file.
    Gabe McArthur, Sep 19, 2006
    #2
    1. Advertising

  3. Also, you may want to post this kind of question to
    comp.unix.programmer instead. I'm not sure if system() is posix (with
    shell redirection and all).
    Gabe McArthur, Sep 19, 2006
    #3
  4. Gabe McArthur <> wrote:

    > Also, you may want to post this kind of question to
    > comp.unix.programmer instead. I'm not sure if system() is posix (with
    > shell redirection and all).


    1) Please include context when replying.

    2) system() is a standard C function, but what it does is
    implementation-defined.

    --
    C. Benson Manica | I *should* know what I'm talking about - if I
    cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Sep 19, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas Bandt
    Replies:
    2
    Views:
    569
    Thomas Bandt
    Feb 9, 2006
  2. Ben Finney
    Replies:
    2
    Views:
    979
    Egor Bolonev
    Jun 30, 2003
  3. Egor Bolonev
    Replies:
    0
    Views:
    470
    Egor Bolonev
    Jun 30, 2003
  4. pratap
    Replies:
    3
    Views:
    444
    James Kanze
    Jul 19, 2007
  5. Replies:
    5
    Views:
    3,414
    James Kanze
    Mar 4, 2008
Loading...

Share This Page