Command Output Redirection
Posted
#1
(In Topic #381)
Trainee
dim strCommand as String
dim strUSBDevices as string
dim myFile as File
strCommand = "lsusb > usb_devices.txt"
shell strCommand
myFile = open "usb_devices.txt" for input
line input #myFile, strUSBDevices
myFile.close
Obviously, you would expect the command to return more than one USB device, so the file would have multiple lines, but you get the point.
My question is this: Is there a way to redirect the output of the Linux command to write directly to a string variable declared in the application, thereby removing the need for the file?
Thanks
Beeza
Posted
Regular

Posted
Guru

Is there a way to redirect the output of the Linux command to write directly to a string variable declared in the application
Yes, you can. In the code below I have redirected the output to the variable 'sTemp'.
The output on my computer is: -
Code
Bus 002 Device 002: ID 8087:8000 Intel Corp.
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:8008 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID 0461:4d64 Primax Electronics, Ltd
Bus 003 Device 002: ID 2a7a:9a18
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubEDIT. Vuott just beat me to this.
EDIT2
Try this code is a new Graphical Application.
Code (gambas)
- .Arrangement = Arrange.Vertical
- .Padding = 5
- .Title = "USB"
- .Columns.Count = 1
- Gridview1[iRow, 0].Text = sLSUSB[iRow]
Posted
Trainee
I'll monitor this forum regularly in the hope that I can similarly help somebody else out in due course.
Beeza
1 guest and 0 members have just viewed this.


