Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 39535
1
###
2
CoCalc: Collaborative web-based SageMath, Jupyter, LaTeX and Terminals.
3
Copyright 2015, SageMath, Inc., GPL v3.
4
5
Execute a command line or block of BASH code
6
###
7
8
winston = require('winston')
9
10
misc = require('smc-util/misc')
11
misc_node = require('smc-util-node/misc_node')
12
message = require('smc-util/message')
13
14
exports.exec_shell_code = (socket, mesg) ->
15
#winston.debug("project_exec: #{misc.to_json(mesg)} in #{process.cwd()}")
16
if mesg.command == "smc-jupyter"
17
socket.write_mesg("json", message.error(id:mesg.id, error:"do not run smc-jupyter directly"))
18
return
19
misc_node.execute_code
20
command : mesg.command
21
args : mesg.args
22
path : misc_node.abspath(mesg.path)
23
timeout : mesg.timeout
24
err_on_exit : mesg.err_on_exit
25
max_output : mesg.max_output
26
bash : mesg.bash
27
cb : (err, out) ->
28
if err
29
30
error = "Error executing command '#{mesg.command}' with args '#{mesg.args}' -- #{err}, #{out?.stdout}, #{out?.stderr}"
31
if error.indexOf("Connection refused") != -1
32
error += "-- Email [email protected] if you need full internet access, which is disabled by default."
33
# Too annoying and doesn't work.
34
#if error.indexOf("=") != -1
35
# error += "-- This is a BASH terminal, not a Sage worksheet. For Sage, use +New and create a Sage worksheet."
36
err_mesg = message.error
37
id : mesg.id
38
error : error
39
socket.write_mesg('json', err_mesg)
40
else
41
#winston.debug(json(out))
42
socket.write_mesg 'json', message.project_exec_output
43
id : mesg.id
44
stdout : out.stdout
45
stderr : out.stderr
46
exit_code : out.exit_code
47
48