manipulating console output.

R

robannexs

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
 
G

Gabe McArthur

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.
 
G

Gabe McArthur

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).
 
C

Christopher Benson-Manica

Gabe McArthur said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top