String HHVM_FUNCTION(exec, const String& command, VRefParam output /* = null */, VRefParam return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command); if (!fp) return empty_string(); StringBuffer sbuf; sbuf.read(fp); Array lines = StringUtil::Explode(sbuf.detach(), "\n").toArray(); int ret = ctx.exit(); if (WIFEXITED(ret)) ret = WEXITSTATUS(ret); return_var = ret; int count = lines.size(); if (count > 0 && lines[count - 1].toString().empty()) { count--; // remove explode()'s last empty line } PackedArrayInit pai(count); for (int i = 0; i < count; i++) { pai.append(lines[i]); } output.wrapped() = pai.toArray(); if (!count || lines.empty()) { return String(); } return HHVM_FN(rtrim)(lines[count - 1].toString()); }
String HHVM_FUNCTION(system, const String& command, VRefParam return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command); if (!fp) return empty_string(); StringBuffer sbuf; if (fp) { sbuf.read(fp); } Array lines = StringUtil::Explode(sbuf.detach(), "\n").toArray(); int ret = ctx.exit(); if (WIFEXITED(ret)) ret = WEXITSTATUS(ret); return_var = ret; int count = lines.size(); if (count > 0 && lines[count - 1].toString().empty()) { count--; // remove explode()'s last empty line } auto& ectx = *g_context; for (int i = 0; i < count; i++) { ectx.write(lines[i].toString()); ectx.write("\n"); } if (!count || lines.empty()) { return String(); } return HHVM_FN(rtrim)(lines[count - 1].toString()); }
String f_exec(const String& command, VRefParam output /* = null */, VRefParam return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command.c_str()); if (!fp) return ""; StringBuffer sbuf; sbuf.read(fp); Array lines = StringUtil::Explode(sbuf.detach(), "\n").toArray(); int ret = ctx.exit(); if (WIFEXITED(ret)) ret = WEXITSTATUS(ret); return_var = ret; int count = lines.size(); if (count > 0 && lines[count - 1].toString().empty()) { count--; // remove explode()'s last empty line } if (!output.is(KindOfArray)) { output = Array(ArrayData::Create()); } for (int i = 0; i < count; i++) { output.append(lines[i]); } if (!count || lines.empty()) { return String(); } return f_rtrim(lines[count - 1].toString()); }
String f_system(const String& command, VRefParam return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command.c_str()); if (!fp) return ""; StringBuffer sbuf; if (fp) { sbuf.read(fp); } Array lines = StringUtil::Explode(sbuf.detach(), "\n").toArray(); int ret = ctx.exit(); if (WIFEXITED(ret)) ret = WEXITSTATUS(ret); return_var = ret; int count = lines.size(); if (count > 0 && lines[count - 1].toString().empty()) { count--; // remove explode()'s last empty line } for (int i = 0; i < count; i++) { echo(lines[i].toString()); echo("\n"); } if (!count || lines.empty()) { return String(); } return f_rtrim(lines[count - 1].toString()); }
String f_system(CStrRef command, Variant return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command); if (!fp) return ""; StringBuffer sbuf; if (fp) { sbuf.read(fp); } Array lines = StringUtil::Explode(sbuf.detach(), "\n"); return_var = ctx.exit(); int count = lines.size(); if (count > 0 && lines[count - 1].toString().empty()) { count--; // remove explode()'s last empty line } for (int i = 0; i < count; i++) { echo(lines[i]); echo("\n"); } if (!count || lines.empty()) { return String(); } return StringUtil::Trim(lines[count - 1], StringUtil::TrimRight); }
String f_exec(CStrRef command, Variant output /* = null */, Variant return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command); if (!fp) return ""; StringBuffer sbuf; sbuf.read(fp); Array lines = StringUtil::Explode(sbuf.detach(), "\n"); return_var = ctx.exit(); int count = lines.size(); if (count > 0 && lines[count - 1].toString().empty()) { count--; // remove explode()'s last empty line } if (!output.is(KindOfArray)) { output = Array(ArrayData::Create()); } for (int i = 0; i < count; i++) { output.append(lines[i]); } if (!count || lines.empty()) { return String(); } return StringUtil::Trim(lines[count - 1], StringUtil::TrimRight); }
void f_passthru(CStrRef command, Variant return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command); if (!fp) return; char buffer[1024]; while (true) { int len = read(fileno(fp), buffer, sizeof(buffer) - 1); if (len == -1 && errno == EINTR) continue; if (len <= 0) break; // break on error or EOF buffer[len] = '\0'; echo(String(buffer, len, AttachLiteral)); } return_var = ctx.exit(); }
void f_passthru(const String& command, VRefParam return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command.c_str()); if (!fp) return; char buffer[1024]; while (true) { int len = read(fileno(fp), buffer, sizeof(buffer) - 1); if (len == -1 && errno == EINTR) continue; if (len <= 0) break; // break on error or EOF buffer[len] = '\0'; echo(String(buffer, len, CopyString)); } int ret = ctx.exit(); if (WIFEXITED(ret)) ret = WEXITSTATUS(ret); return_var = ret; }
void HHVM_FUNCTION(passthru, const String& command, VRefParam return_var /* = null */) { ShellExecContext ctx; FILE *fp = ctx.exec(command); if (!fp) return; char buffer[1024]; while (true) { int len = read(fileno(fp), buffer, sizeof(buffer) - 1); if (len == -1 && errno == EINTR) continue; if (len <= 0) break; // break on error or EOF buffer[len] = '\0'; g_context->write(String(buffer, len, CopyString)); } int ret = ctx.exit(); MAYBE_WIFEXITED(ret); return_var.assignIfRef(ret); }