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

  • #1
126
3
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.
 

Answers and Replies

  • #3
Stephen Tashi
Science Advisor
7,543
1,455
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.
 
  • #4
34,517
6,208
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.
 

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

Replies
9
Views
1K
  • Last Post
Replies
6
Views
45K
Replies
10
Views
10K
Replies
5
Views
9K
  • Last Post
Replies
2
Views
2K
Replies
2
Views
5K
Replies
1
Views
4K
  • Last Post
Replies
14
Views
2K
  • Last Post
Replies
0
Views
5K
Replies
22
Views
1K
Top