Search code examples
cawksystem

Invoke system() in C program twice in one line


I am trying to invoke the system() command twice in one line. When compiling the code it does not seem to like the second instance of system() which is used to execute a script using awk output.

Code snippet:

int main()
{
system("lsusb | sudo awk '/Terminus.*Hub$/{ system("/usr/bin/usbreset " $6) }'");
}

As you can see in the code interpreter /usr/bin/usbreset is no longer declared as a string and is causing the compilation error.


Solution

  • You need to escape the inner quotes.

    Try:

    "lsusb | sudo awk '/Terminus.*Hub$/{ system(\"/usr/bin/usbreset \" $6) }'"