How to get Hard Disk serial number using C++ program in linux
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
thank you for replying
@fpmurphy:
Every time i compile and run this program it gives me the error as follows
ERROR: Cannot open device (null)
thanks
@knudfl;
i used the command it worked..but i want this in the form of a c or cpp code..
thanks
Ok...you do realize that you will actually have to modify that code, and do some work on your own, to make it function, right??? That was sample code, to show you how to to it yourself. We're not going to write code for you.
is there any way that i can write a code in cpp which will execute the command "hdparm -i /dev/hda" command and then i can get the hdd serial number ??
is there any way that i can write a code in cpp which will execute the command "hdparm -i /dev/hda" command and then i can get the hdd serial number ??
thanks
Yes, there is, easily. You'd do it the same way you would run any other system command.
However, you haven't yet shown us any of the work you've done, or what you've tried.
int main()
{
system("hdparm -i /dev/hda | grep -i serial");
}
and i got the output as:
[root@localhost anuradha]# g++ hddid.cpp -o hddid
hddid.cpp:9:2: warning: no newline at end of file
[root@localhost anuradha]# ./hddid
Model=SAMSUNG SP0802N, FwRev=TK200-04, SerialNo=S00JJ20X897934
[root@localhost anuradha]#
what i need is.. i should be able to use the output further in my code...
i dont have any handle or variable where this output is stored..
so that i can use it further..
Distribution: pclos2010.12, Slack1337 DebSqueeze, +50+ other Linux OS, for test only.
Posts: 9,308
Rep:
Quote:
What i need is..
I should be able to use the output further in my code...
Well, I guess you in some way can redirect the result
and read it later.
....... Like you would do with a command:
hdparm -i /dev/hda | grep -i serial > /var/log/serial.no
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.