How to read a list of USB from C++ in ubuntu OS?

Join the discussion
Registration is free. Start your own thread to ask a follow-up.
3 replies · 3K views
Nate Duong
Messages
125
Reaction score
4
I am trying to use C++ (eclipse in Ubuntu OS) to read USB connection. Usually, on the terminal window, I can use command "lsusb" to see the list. Now, I want to do the same way with C++.

can anyone help?

Thank you very much.
 
Physics news on Phys.org
The man page for lsusb provides the necessary info ie what files to read:

http://linuxcommand.org/man_pages/lsusb8.html

Notice the /proc/bus/usb directory and the file /usr/share/usb.ids
 
jedishrfu said:
The man page for lsusb provides the necessary info ie what files to read:

http://linuxcommand.org/man_pages/lsusb8.html

Notice the /proc/bus/usb directory and the file /usr/share/usb.ids

But is the question how get the list of usb connections within a C++ program instead of from the command line?

In C there is a command "system(...)" isn't there? it returns information in a string, so it is awkward to use.

Edit: I see - you're suggesting he read the files from the C++ program. That would still mean getting information in the form of strings, I suppose.
 
Stephen Tashi said:
In C there is a command "system(...)" isn't there? it returns information in a string, so it is awkward to use.
No, the system() function returns an int, typically a status code that is returned by whatever system command was called.