By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

manipulating console output.

P: n/a
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 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

Sep 19 '06 #2

P: n/a
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).

Sep 19 '06 #3

P: n/a
Gabe McArthur <ma********@gmail.comwrote:
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.
Sep 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.