Could someone write an example program that opens up firefox? I would really like to see the syntax to do that.

Thanks

Dani AI

Generated

Several replies here take the quick-and-dirty route of invoking a shell; and showed that approach and was right to point out its drawbacks. Invoking the shell is fine for a throwaway test, but it spawns an extra shell process, can leave a visible console, and is vulnerable to command‑injection if you pass untrusted text. For reliable control on Windows use the Win32 Shell APIs (ShellExecute/ShellExecuteEx) or CreateProcess, and if you want no console window either hide your own console at runtime or build the program as a GUI subsystem.

A practical CreateProcess pattern that starts a child without showing a console (works for console-style children) and avoids the shell:

#include <windows.h>
#include <string>

bool LaunchHidden(const std::wstring& commandLine)
{
    STARTUPINFOW si = { sizeof(si) };
    PROCESS_INFORMATION pi;
    si.dwFlags = STARTF_USESHOWWINDOW;
    si.wShowWindow = SW_HIDE;

    std::wstring cmd = commandLine; // CreateProcess modifies the buffer
    BOOL ok = CreateProcessW(nullptr, &cmd[0], nullptr, nullptr, FALSE,
                             CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi);
    if (!ok) return false;
    CloseHandle(pi.hThread);
    CloseHandle(pi.hProcess);
    return true;
}

If the goal is merely to hide the calling console, keep it simple:

#include <windows.h>

void HideConsoleWindow()
{
    HWND h = GetConsoleWindow();
    if (h) ShowWindow(h, SW_HIDE);
}

On non‑Windows systems use the native mechanisms (fork/exec or the desktop opener such as xdg-open on many Linux desktops, open on macOS). Always validate and quote paths or arguments and prefer APIs that accept argument vectors rather than assembling a shell command string. For locating the user’s default browser on Windows you can read the relevant registry entry (for example under HKEY_CLASSES_ROOT\http\shell\open\command) rather than hardcoding executable paths.

Recommended Answers

All 8 Replies

system("start http://www.google.com");
or system("C:\\Program Files\\Mozilla Firefox\\firefox.exe");

Try, system ( "start firefox" ) ;

Alright thanks guys and what is the command to make the dos window hide?

"Hide the dos window" - is it possible? I don't know.
If you want to close the dos window right after opening Firefox then a simple return 0 following system() should work.

Others answers are wrong.
Never use System() on Win32 (creates another PAS)
Use Shell apis.

Others answers are wrong.
Never use System() on Win32 (creates another PAS)
Use Shell apis.

ShodoNinja never said it is a Win32 program

system ( "start firefox" ) ; doesnt work under linux

is there an alternative?

----------------------------------

never mind.. linux doesnt need start

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.