Guest User

Untitled

a guest
Jun 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. ## js_system.cc
  2.  
  3. JS_METHOD(_exec) {
  4. if (args.Length() != 1) {
  5. return JS_EXCEPTION("Wrong argument count. Use system.exec(\"command\")");
  6. }
  7.  
  8. std::string data;
  9. FILE *stream;
  10. int MAX_BUFFER = 256;
  11. char buffer[MAX_BUFFER];
  12.  
  13. v8::String::Utf8Value cmd(args[0]);
  14. stream = popen(*cmd, "r");
  15. while ( fgets(buffer, MAX_BUFFER, stream) != NULL ) {
  16. data.append(buffer);
  17. }
  18. pclose(stream);
  19. return JS_STR(data.data());
  20. }
  21.  
  22.  
  23. ## js_system.cc | inside setup_system()
  24.  
  25. system->Set(JS_STR("exec"), v8::FunctionTemplate::New(_exec)->GetFunction());
Add Comment
Please, Sign In to add comment