Beaker
Beaker

Reputation: 67

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.

Upvotes: 0

Views: 80

Answers (1)

miravalls
miravalls

Reputation: 365

You need to escape the inner quotes.

Try:

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

Upvotes: 2

Related Questions