Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## js_system.cc
- JS_METHOD(_exec) {
- if (args.Length() != 1) {
- return JS_EXCEPTION("Wrong argument count. Use system.exec(\"command\")");
- }
- std::string data;
- FILE *stream;
- int MAX_BUFFER = 256;
- char buffer[MAX_BUFFER];
- v8::String::Utf8Value cmd(args[0]);
- stream = popen(*cmd, "r");
- while ( fgets(buffer, MAX_BUFFER, stream) != NULL ) {
- data.append(buffer);
- }
- pclose(stream);
- return JS_STR(data.data());
- }
- ## js_system.cc | inside setup_system()
- system->Set(JS_STR("exec"), v8::FunctionTemplate::New(_exec)->GetFunction());
Add Comment
Please, Sign In to add comment