/* * Start the user's default browser */ static int runBrowser(char *page) { PROCESS_INFORMATION procInfo; STARTUPINFO startInfo; char cmdBuf[MPR_MAX_STRING]; char *path; char *pathArg; int port; port = getAppwebPort(); if (port < 0) { mprError(mpr, "Can't get Appweb listening port"); return -1; } path = getBrowserPath(MPR_MAX_STRING); if (path == 0) { mprError(mpr, "Can't get browser startup command"); return -1; } pathArg = strstr(path, "\"%1\""); if (*page == '/') { page++; } if (pathArg == 0) { mprSprintf(cmdBuf, MPR_MAX_STRING, "%s http://localhost:%d/%s", path, port, page); } else { /* * Patch out the "%1" */ *pathArg = '\0'; mprSprintf(cmdBuf, MPR_MAX_STRING, "%s \"http://localhost:%d/%s\"", path, port, page); } mprLog(mpr, 4, "Running %s\n", cmdBuf); memset(&startInfo, 0, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); if (! CreateProcess(0, cmdBuf, 0, 0, FALSE, 0, 0, 0, &startInfo, &procInfo)) { mprError(mpr, "Can't create process: %s, %d", cmdBuf, mprGetOsError()); return -1; } CloseHandle(procInfo.hProcess); mprFree(path); return 0; }
/* Start the user's default browser */ static int runBrowser(char *page) { PROCESS_INFORMATION procInfo; STARTUPINFO startInfo; char cmdBuf[ME_MAX_BUFFER]; char *path; char *pathArg; int port; port = getAppwebPort(); if (port < 0) { mprError("appweb monitor", "Cannot get Appweb listening port"); return -1; } path = getBrowserPath(ME_MAX_BUFFER); if (path == 0) { mprError("appweb monitor", "Cannot get browser startup command"); return -1; } pathArg = strstr(path, "\"%1\""); if (*page == '/') { page++; } if (sstarts(page, "http")) { fmt(cmdBuf, ME_MAX_BUFFER, "%s %s", path, page); } else if (pathArg == 0) { fmt(cmdBuf, ME_MAX_BUFFER, "%s http://localhost:%d/%s", path, port, page); } else { *pathArg = '\0'; fmt(cmdBuf, ME_MAX_BUFFER, "%s \"http://localhost:%d/%s\"", path, port, page); } mprLog("appweb monitor", 4, "Running %s\n", cmdBuf); memset(&startInfo, 0, sizeof(startInfo)); startInfo.cb = sizeof(startInfo); if (! CreateProcess(0, cmdBuf, 0, 0, FALSE, 0, 0, 0, &startInfo, &procInfo)) { mprError("appweb monitor", "Cannot create process: %s, %d", cmdBuf, mprGetOsError()); return -1; } CloseHandle(procInfo.hProcess); return 0; }