static int runCommand(HttpConn *conn, cchar *command, cchar *csource, cchar *module) { EspReq *req; EspRoute *eroute; MprCmd *cmd; MprKey *var; MprList *elist; cchar **env; char *err, *out; req = conn->data; eroute = req->route->eroute; cmd = mprCreateCmd(conn->dispatcher); if ((req->commandLine = espExpandCommand(eroute, command, csource, module)) == 0) { httpError(conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "Missing EspCompile directive for %s", csource); return MPR_ERR_CANT_READ; } mprLog(4, "ESP command: %s\n", req->commandLine); if (eroute->env) { elist = mprCreateList(0, 0); for (ITERATE_KEYS(eroute->env, var)) { mprAddItem(elist, sfmt("%s=%s", var->key, var->data)); } mprAddNullItem(elist); env = (cchar**) &elist->items[0]; } else {
static int runCommand(HttpRoute *route, MprDispatcher *dispatcher, cchar *command, cchar *csource, cchar *module, char **errMsg) { MprCmd *cmd; MprKey *var; MprList *elist; EspRoute *eroute; cchar **env, *commandLine; char *err, *out; int rc; *errMsg = 0; eroute = route->eroute; cmd = mprCreateCmd(dispatcher); if ((commandLine = espExpandCommand(route, command, csource, module)) == 0) { *errMsg = sfmt("Missing EspCompile directive for %s", csource); return MPR_ERR_CANT_READ; } mprTrace(4, "ESP command: %s\n", commandLine); if (eroute->env) { elist = mprCreateList(0, MPR_LIST_STABLE); for (ITERATE_KEYS(eroute->env, var)) { mprAddItem(elist, sfmt("%s=%s", var->key, var->data)); } mprAddNullItem(elist); env = (cchar**) &elist->items[0]; } else {
static int runCommand(HttpConn *conn, cchar *command, cchar *csource, cchar *module) { EspReq *req; EspRoute *eroute; MprCmd *cmd; char *err, *out; req = conn->data; eroute = req->route->eroute; cmd = mprCreateCmd(conn->dispatcher); if ((req->commandLine = espExpandCommand(command, csource, module)) == 0) { httpError(conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "Missing EspCompile directive for %s", csource); return MPR_ERR_CANT_READ; } mprLog(4, "ESP command: %s\n", req->commandLine); if (eroute->env) { mprAddNullItem(eroute->env); mprSetCmdDefaultEnv(cmd, (cchar**) &eroute->env->items[0]); } if (eroute->searchPath) { mprSetCmdSearchPath(cmd, eroute->searchPath); } // WARNING: GC will run here if (mprRunCmd(cmd, req->commandLine, &out, &err, -1, 0) != 0) { if (err == 0 || *err == '\0') { /* Windows puts errors to stdout Ugh! */ err = out; } if (eroute->showErrors) { httpError(conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "Can't run command %s, error %s", req->commandLine, err); } else { mprError("ESP: Can't run command %s, error %s", req->commandLine, err); httpError(conn, HTTP_CODE_INTERNAL_SERVER_ERROR, "Can't compile view"); } return MPR_ERR_CANT_COMPLETE; } return 0; }