winston = require('winston')
misc = require('smc-util/misc')
misc_node = require('smc-util-node/misc_node')
message = require('smc-util/message')
exports.exec_shell_code = (socket, mesg) ->
if mesg.command == "smc-jupyter"
socket.write_mesg("json", message.error(id:mesg.id, error:"do not run smc-jupyter directly"))
return
misc_node.execute_code
command : mesg.command
args : mesg.args
path : misc_node.abspath(mesg.path)
timeout : mesg.timeout
err_on_exit : mesg.err_on_exit
max_output : mesg.max_output
bash : mesg.bash
cb : (err, out) ->
if err
error = "Error executing command '#{mesg.command}' with args '#{mesg.args}' -- #{err}, #{out?.stdout}, #{out?.stderr}"
if error.indexOf("Connection refused") != -1
error += "-- Email [email protected] if you need full internet access, which is disabled by default."
err_mesg = message.error
id : mesg.id
error : error
socket.write_mesg('json', err_mesg)
else
socket.write_mesg 'json', message.project_exec_output
id : mesg.id
stdout : out.stdout
stderr : out.stderr
exit_code : out.exit_code