running BASH commands from C++

1,417 views
Skip to first unread message

Dhanushka Jayaweera

unread,
Dec 21, 2013, 11:04:02 AM12/21/13
to beagl...@googlegroups.com
hey guys,

I want to add this bash command to my c++ program. 
echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots

i tried this
#include<cstdio>
#include<cstdlib>
#include<unistd.h>
using namespace std;
int main() {
    system("echo cape-bone-iio > /sys/devices/bone_capemgr.*/slots");
    return 0;
}

but it does not work. 

Can someone help me with this?

Bas Laarhoven

unread,
Dec 21, 2013, 11:10:04 AM12/21/13
to beagl...@googlegroups.com
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Have you verified that the system command does wildcard expansion?
(Replace the asterisk in the command by the proper number and verify whether that works)

-- Bas

Dhanushka Jayaweera

unread,
Dec 21, 2013, 11:22:27 AM12/21/13
to beagl...@googlegroups.com
well i tried this 
system("echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots");

still the same

Dhanushka Jayaweera

unread,
Dec 21, 2013, 11:24:47 AM12/21/13
to beagl...@googlegroups.com
both commands work in the terminal

Bas Laarhoven

unread,
Dec 21, 2013, 11:37:30 AM12/21/13
to beagl...@googlegroups.com
On 21-12-2013 17:24, Dhanushka Jayaweera wrote:
both commands work in the terminal

So you know what to do, now find out how to do it :-)
What is the result from the system() call?

-- Bas

BTW: You can also try writing the proper text directly to the slots file!
Message has been deleted

Dhanushka Jayaweera

unread,
Dec 21, 2013, 11:49:41 AM12/21/13
to beagl...@googlegroups.com
im getting nothing.. no errors. but it wont write the file either  :(
im pretty new to BBB, its just my 5th day of using it... and I did some googling, couldn't find a solution yet..

im using  "echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots"  to create the file for ADC. right now i have to execute the bash command manually before i execute the c++ file which I wrote to read ADC values

Btw what is  "writing the proper text directly to the slots file" ?? im kinda lost 

David Lambert

unread,
Dec 21, 2013, 3:34:47 PM12/21/13
to beagl...@googlegroups.com
Have you tried looking at the return status of the "system" call. That may give a clue. Also it may be worth explicitly giving the path for echo:

int status;
status =  system("/bin/echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots");
printf("status = %d\n", status);


HTH,

Dave.

Dhanushka Jayaweera

unread,
Dec 21, 2013, 9:35:50 PM12/21/13
to beagl...@googlegroups.com
hey guys,

system("/bin/echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots");   -   works 
I simply forgot a header file :/

#include <fstream>  //has to be in the code

Reply all
Reply to author
Forward
0 new messages