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

Click For Summary

Discussion Overview

The discussion revolves around how to read a list of USB connections using C++ on Ubuntu OS. Participants explore methods to achieve this, comparing command line approaches with programmatic solutions.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant seeks assistance in using C++ to replicate the functionality of the "lsusb" command, which lists USB connections.
  • Another participant references the man page for "lsusb," suggesting that it provides information on relevant files to read, specifically mentioning the /proc/bus/usb directory and /usr/share/usb.ids file.
  • A participant questions whether the original inquiry is about obtaining the list of USB connections within a C++ program rather than from the command line.
  • There is a discussion about the "system(...)" command in C, with one participant noting that it returns an int, typically a status code, rather than the output of the command, which complicates its use for this purpose.
  • Another participant suggests that reading the files directly from the C++ program would still result in obtaining information in string format.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the best approach to read USB connections in C++. There are differing views on the utility of the "system(...)" command and the implications of reading files directly.

Contextual Notes

There are limitations regarding the clarity of how to handle the output from system commands and the format of data retrieved from the suggested files.

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.
 
Technology 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.
 

Similar threads

  • · Replies 30 ·
2
Replies
30
Views
5K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 2 ·
Replies
2
Views
949
  • · Replies 9 ·
Replies
9
Views
2K
Replies
2
Views
2K
  • · Replies 15 ·
Replies
15
Views
8K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 27 ·
Replies
27
Views
17K
Replies
1
Views
2K
Replies
14
Views
4K