UNPKG

@cocalc/project

Version:
72 lines (64 loc) 2.57 kB
// Generated by CoffeeScript 2.5.1 (function() { //######################################################################## // This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. // License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details //######################################################################## var message, misc, misc_node; /* CoCalc: Collaborative web-based SageMath, Jupyter, LaTeX and Terminals. Copyright 2015, SageMath, Inc., GPL v3. Execute a command line or block of BASH code */ //winston = require('./logger').getLogger('exec-shell-code') misc = require('@cocalc/util/misc'); misc_node = require('@cocalc/backend/misc_node'); message = require('@cocalc/util/message'); exports.exec_shell_code = function(socket, mesg) { var ref; //winston.debug("project_exec: #{misc.to_json(mesg)} in #{process.cwd()}") if (mesg.command === "smc-jupyter") { socket.write_mesg("json", message.error({ id: mesg.id, error: "do not run smc-jupyter directly" })); return; } return misc_node.execute_code({ command: mesg.command, args: mesg.args, path: misc_node.abspath((ref = mesg.path) != null ? ref : ""), timeout: mesg.timeout, err_on_exit: mesg.err_on_exit, max_output: mesg.max_output, aggregate: mesg.aggregate, bash: mesg.bash, cb: function(err, out) { var err_mesg, error; if (err) { error = `Error executing command '${mesg.command}' with args '${mesg.args}' -- ${err}, ${out != null ? out.stdout : void 0}, ${out != null ? out.stderr : void 0}`; if (error.indexOf("Connection refused") !== -1) { error += "-- Email help@cocalc.com if you need full internet access, which is disabled by default."; } // Too annoying and doesn't work. //if error.indexOf("=") != -1 // error += "-- This is a BASH terminal, not a Sage worksheet. For Sage, use +New and create a Sage worksheet." err_mesg = message.error({ id: mesg.id, error: error }); return socket.write_mesg('json', err_mesg); } else { //winston.debug(json(out)) return socket.write_mesg('json', message.project_exec_output({ id: mesg.id, stdout: out.stdout, stderr: out.stderr, exit_code: out.exit_code })); } } }); }; }).call(this); //# sourceMappingURL=exec_shell_code.js.map