For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2006 > manipulating console output









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author manipulating console output
robannexs@gmail.com

2006-09-19, 4:00 am

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 do to not 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

Ido.Yehieli@gmail.com

2006-09-19, 8:01 am

robannexs@gmail.com wrote:
> system("sudo dd if=/dev/sda of=mbr.bin bs=512 count=1");
>
> This is the output i got from console.

<SNIP>
> is there anyway I can do to not print these messages? or capture them
> and do some parsing such that i will be able to print my own messages?


Not sure if that will work, but maybe you can redirect it to a some
temporary file:

system("sudo dd if=/dev/sda of=mbr.bin bs=512 count=1 >
some_temporary_file");

and then read that file afterwards.

Hope that helped,
Ido.

ilko.k.v@gmail.com

2006-09-19, 8:01 am


robannexs@gmail.com wrote:
> 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 do to not 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


Try with system call popen

Chris F.A. Johnson

2006-09-19, 7:02 pm

On 2006-09-19, robannexs@gmail.com wrote:
> 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 do to not print these messages? or capture them
> and
> do some parsing such that i will be able to print my own messages?


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

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
Nico

2006-09-19, 7:02 pm


robannexs@gmail.com wrote:
> 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 do to not print these messages? or capture them
> and
> do some parsing such that i will be able to print my own messages?


Have you tried system("@sudo dd if=/dev/sda of=mbr.bin bs=512
count=1"); ?

Barry Margolin

2006-09-20, 4:00 am

In article <1158690340.621167.38820@b28g2000cwb.googlegroups.com>,
"Nico" <listas@nicolasb.com.ar> wrote:

> robannexs@gmail.com wrote:
>
> Have you tried system("@sudo dd if=/dev/sda of=mbr.bin bs=512
> count=1"); ?


What do you expect that to do? There's no "@sudo" command that I've
heard of. Are you expecting this to work because you've seen Makefiles
that use the "@" prefix? First of all, that prevents the command from
being echoed, it has no effect on the command's output. And second,
that's something done by make, not the shell.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com