Hello everybody!

I build a string for a system call (Matlab) like:

std::string command = "matlab -nosplash -r MyMatlabScript(" + arg1 + " " + arg2 + ");";

The system call is:

system(command.c_str());

However, i get an error, pointing to the first parentheses in my command string.

How can i use a "(" sign in my system call?

Thanks a lot,

#EO

Recommended Answers

All 3 Replies

I used Windows 7 and did not have a problem with that code snippet,

#include <string>
using std::string;

int main(int argc, char**argv)
{
	string arg1 = "one";
	string arg2 = "two";
	string command = "matlab -nosplash -r MyMatlabScript(" + arg1 + " " + arg2 + ");";
	system(command.c_str());
}
'matlab' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .

I used Windows 7 and did not have a problem with that code snippet,

#include <string>
using std::string;

int main(int argc, char**argv)
{
	string arg1 = "one";
	string arg2 = "two";
	string command = "matlab -nosplash -r MyMatlabScript(" + arg1 + " " + arg2 + ");";
	system(command.c_str());
}
'matlab' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .

Thanks for trying this. Matlab is a program and MyMatlabScript.m is function which can take two arguments. I do not think there is a problem with Matlab, but how can i include "(" in my system call. I am working on Linux terminal.

*nix shell is probably interpreting the ( character. you might try escaping it, e.g. \(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.