Execute command and get output to variable

Hello,

i would like to execute on my raspberry a command and save it to a variable to show it on my blynk app.

what is working so far:


BLYNK_WRITE(V5)
{
    int state = param.asInt();
  if ( state == 1)
 {
          system(" lp -d Zebra_Technologies_ZTC_GK420d /home/pi/Blynk/Projects/Zebra_Empty_file_Print.txt");
 }
}

but i also want to do something like this which is not working:

BLYNK_WRITE(V6)
{
    int state = param.asInt();
  if ( state == 1)
 {
	 int zebra_count = 0;
         zebra_count = system("lpstat -o Zebra_Technologies_ZTC_GK420d | wc -l");
	Blynk.virtualWrite(V7, zebra_count);  
 }
}

if this does not work, is there a way to read like a .txt file and save it to a variable?

This isn’t really Blynk related questions… and you’ll probably get better answers elsewhere :stuck_out_tongue:

I’d try to get it to work as a standalone application before puttin’ it into Blynk.

Some links:

https://en.cppreference.com/w/cpp/utility/program/system
http://www.cplusplus.com/

1 Like