##// END OF EJS Templates
Prevent !cmd to try to run backgrounded (cmd &) processes.
Fernando Perez -
Show More
@@ -13,6 +13,8 b' machinery. This should thus be thought of as scaffolding.'
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14 # Imports
14 # Imports
15 #-----------------------------------------------------------------------------
15 #-----------------------------------------------------------------------------
16 from __future__ import print_function
17
16 # Stdlib
18 # Stdlib
17 import inspect
19 import inspect
18 import os
20 import os
@@ -82,16 +84,23 b' class ZMQInteractiveShell(InteractiveShell):'
82 displayhook_class = Type(ZMQDisplayHook)
84 displayhook_class = Type(ZMQDisplayHook)
83
85
84 def system(self, cmd):
86 def system(self, cmd):
85 cmd = self.var_expand(cmd, depth=2)
87 cmd = self.var_expand(cmd, depth=2).strip()
88
89 # Runnning a bacgkrounded process from within the gui isn't supported
90 # because we do p.wait() at the end. So instead of silently blocking
91 # we simply refuse to run in this mode, to avoid surprising the user.
92 if cmd.endswith('&'):
93 raise OSError("Background processes not supported.")
94
86 sys.stdout.flush()
95 sys.stdout.flush()
87 sys.stderr.flush()
96 sys.stderr.flush()
88 p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
97 p = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
89 for line in p.stdout.read().split('\n'):
98 for line in p.stdout.read().split('\n'):
90 if len(line) > 0:
99 if len(line) > 0:
91 print line
100 print(line)
92 for line in p.stderr.read().split('\n'):
101 for line in p.stderr.read().split('\n'):
93 if len(line) > 0:
102 if len(line) > 0:
94 print line
103 print(line, file=sys.stderr)
95 p.wait()
104 p.wait()
96
105
97 def init_io(self):
106 def init_io(self):
@@ -375,7 +384,7 b' class ZMQInteractiveShell(InteractiveShell):'
375
384
376 if use_temp:
385 if use_temp:
377 filename = self.shell.mktempfile(data)
386 filename = self.shell.mktempfile(data)
378 print 'IPython will make a temporary file named:',filename
387 print('IPython will make a temporary file named:', filename)
379
388
380 # Make sure we send to the client an absolute path, in case the working
389 # Make sure we send to the client an absolute path, in case the working
381 # directory of client and kernel don't match
390 # directory of client and kernel don't match
General Comments 0
You need to be logged in to leave comments. Login now