Take the 2-minute tour ×

for now this is my code. This command will execute a script and supposed to return Safari browser version on Mac if its run in the Terminal.

int versionResult = system("osascript /Library/Application\\ Support/Version.scpt");

In C++, this wil return 1 or 0.

How can I make it return the result of the command in C++?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

You can't do it with system; there's no platform-independent way to do it without using a cross-platform framework like Qt. That looks like a Mac command; to do this on the Mac, which is Unix-like, you could use popen(), something like

char buffer[100];
FILE * f = popen("osascript /Library/Application\\ Support/Version.scpt", "r");
fgets(buffer, 99, f);

buffer gets the output of the command as a character string.

share|improve this answer
add comment

Your Answer


