static void run(io::unbuffered_stream_base &input, io::unbuffered_stream_base &output, const rstd::vector<rel::rlang::token> &tokens) { // Split the arguments into a hostname and the rest. rstd::vector<rstd::vector<rel::rlang::token> > expressions = rel::rlang::compiler::split_expressions(tokens); NP1_ASSERT(expressions.size() >= 2, "meta.remote expects a hostname argument and a script argument"); rstd::string hostname = rel::rlang::compiler::eval_to_string_only(expressions[0]); // Get the rest of the arguments as a string. rstd::vector<rstd::vector<rel::rlang::token> >::const_iterator i = expressions.begin(); ++i; // Skip over the hostname. rstd::vector<rstd::vector<rel::rlang::token> >::const_iterator iz = expressions.end(); rstd::string r17_script; io::string_output_stream r17_script_sos(r17_script); for (; i != iz; ++i) { rel::rlang::io::token_writer::mandatory_write(r17_script_sos, *i); } r17_script_sos.write(';'); // Escape the string for use on a bash command line. rstd::string escaped_r17_script; io::string_output_stream escaped_r17_script_sos(escaped_r17_script); str::write_bash_escaped_string(r17_script, escaped_r17_script_sos); // Prepare the arguments ready for the exec. rstd::vector<rstd::string> exec_args; exec_args.push_back("ssh"); exec_args.push_back(hostname); exec_args.push_back("r17"); exec_args.push_back(escaped_r17_script); // Fork then exec so that we can return just like the other operators do and // so we can do useful things with stderr. int stderr_pipe[2]; process::mandatory_pipe_create(stderr_pipe); pid_t ssh_child_pid = process::mandatory_fork(); if (0 == ssh_child_pid) { // Child. close(stderr_pipe[0]); // If the host is localhost then just execute the script without the cost // of an exec if (str::cmp(hostname, "localhost") == 0) { io::file output_file; dup2(stderr_pipe[1], 2); script_run(input, output, r17_script, false); exit(0); } else { process::mandatory_execvp(exec_args, input.handle(), output.handle(), stderr_pipe[1]); NP1_ASSERT(false, "Unreachable code after mandatory_execvp"); } } // Parent. Read stderr stream. close(stderr_pipe[1]); read_and_prefix_stderr(hostname, stderr_pipe[0]); process::mandatory_wait_for_child(ssh_child_pid); }
int main(int argc, char **argv) #endif { // NOTE: somehow when defining script as a public member of SampleApp, Listener won't return the correct reference to lua refs. No problem if the ref is called within SampleApp // I think this has to do with the map, with char* as key. the address might have changed SCRIPT = script_new(); script_bind(SCRIPT); script_run(SCRIPT, "autoexec.lua"); std::cout << script_stack_size(SCRIPT) << std::endl; printf("address of script: %d\n", SCRIPT); //std::cout << script_stack_size(SCRIPT) << std::endl; //lua_pushinteger(SCRIPT->L, 1); //script_pcallback(SCRIPT, "game.on_mouseclick", 1, 0); //script_stack_pop(SCRIPT, 0); //std::cout << script_stack_size(SCRIPT) << std::endl; srand(time(NULL)); try { APP = new SampleApp(); APP->go(); } catch (Ogre::Exception& e) { #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occured!", MB_OK | MB_ICONERROR | MB_TASKMODAL); #else std::cerr << "Exception:\n"; std::cerr << e.getFullDescription().c_str() << "\n"; #endif return 1; } delete APP; script_free(SCRIPT); return 0; }
/* SCRIPT *script_new(gchar * file, gchar * name) { SCRIPT *ret; ret = g_new0(SCRIPT, 1); ret->file = g_strdup(file); g_strstrip(ret->file); if (name) ret->name = g_strdup(name); return ret; } void script_delete(SCRIPT * script) { if (!script) return; if (script->file) g_free(script->file); if (script->name) g_free(script->name); g_free(script); } */ int script_execute(SESSION_STATE * session, ATM* atm, const gchar *backrefs[], gsize backrefcnt) { int i, ret; gchar *code = g_strdup(""); for (i = 0; i < backrefcnt; ++i) { gchar *t = g_strdup_printf("%s_%d=\"%s\"\n", code, i, backrefs[i]); g_free(code); code = t; } ret = script_run(atm, session, code); g_free(code); return ret; }
int main(int argc, char** argv) { /* If no args are specified... */ if (argc == 1) { puts(HELP_MSG); return 1; } /* Set defaults */ os_detect(); g_filename = DEFAULT; g_cc = NULL; g_dotnet = NULL; g_verbose = 0; /* Process any options that will effect script processing */ arg_set(argc, argv); if (!preprocess()) return 1; /* chdir() to the directory containing the project script, so that * relative paths may be used in the script */ io_chdir(path_getdir(g_filename)); /* Now run the script */ g_hasScript = script_run(g_filename); if (g_hasScript < 0) { puts("** Script failed to run, ending."); return 1; } /* Process any options that depend on the script output */ arg_reset(); if (!postprocess()) return 1; /* All done */ if (g_hasScript) script_close(); prj_close(); return 0; }
int main(int argc, char **argv) { struct timemaster_config *config; struct script *script; char *progname, *config_path = NULL; int c, ret = 0, log_stdout = 0, log_syslog = 1, dry_run = 0; progname = strrchr(argv[0], '/'); progname = progname ? progname + 1 : argv[0]; print_set_progname(progname); print_set_verbose(1); print_set_syslog(0); while (EOF != (c = getopt(argc, argv, "f:nl:mqvh"))) { switch (c) { case 'f': config_path = optarg; break; case 'n': dry_run = 1; break; case 'l': print_set_level(atoi(optarg)); break; case 'm': log_stdout = 1; break; case 'q': log_syslog = 0; break; case 'v': version_show(stdout); return 0; case 'h': usage(progname); return 0; default: usage(progname); return 1; } } if (!config_path) { pr_err("no configuration file specified"); return 1; } config = config_parse(config_path); if (!config) return 1; script = script_create(config); config_destroy(config); if (!script) return 1; print_set_verbose(log_stdout); print_set_syslog(log_syslog); if (dry_run) script_print(script); else ret = script_run(script); script_destroy(script); if (!dry_run) pr_info("exiting"); return ret; }