views:

77

answers:

3

Hey there,

I am attempting to open Firefox using C++ on Linux (Ubuntu). However, I get an segmentation fault. What am I doing wrong, and what should I do?

std::cout << system("/usr/bin/firefox") << std::endl;

I hope to hear from you.

Kind regards,

Machiel

+2  A: 

That code is correct. It will output Firefox's termination code, with a newline. Something else is causing your segmentation fault.

Matthew Flaschen
When I use a debugger to check my program, firefox starts, otherwise it just gives me a Segmentation Fault.
Machiel
+1  A: 

Try running /usr/bin/firefox in a command-line, and check if it works there. This looks like a problem with your firefox, not your code (the part you pasted is correct).

houbysoft
/usr/bin/firefox works fine
Machiel
A: 

To answer my own question:

It works fine, as posted a few times above. The problem was that I was using Netbeans. Netbeans caused a Segmentation Fault when trying to run it. Running outside Netbeans gave the expected result.

Nothing wrong with the code, just with Netbeans, strangely enough.

So everyone with the same error, try run it outside Netbeans.

Machiel