Skip to content

Commit ec6d7a9

Browse files
author
Doug Blank
committed
Allow input from stdin (can't combine with input though)
1 parent e6b2d72 commit ec6d7a9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

jupyter_client/runapp.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,21 @@ def init_kernel_info(self):
104104
def start(self):
105105
self.log.debug("jupyter run: starting...")
106106
super(RunApp, self).start()
107-
for filename in self.filenames_to_run:
108-
self.log.debug("jupyter run: executing `%s`" % filename)
109-
with open(filename) as fp:
110-
code = fp.read()
111-
reply = self.kernel_client.execute(code, reply=True)
112-
return_code = 0 if reply['content']['status'] == 'ok' else 1
113-
if return_code:
114-
raise Exception("jupyter-run error running '%s'" % filename)
107+
if self.filenames_to_run:
108+
for filename in self.filenames_to_run:
109+
self.log.debug("jupyter run: executing `%s`" % filename)
110+
with open(filename) as fp:
111+
code = fp.read()
112+
reply = self.kernel_client.execute(code, reply=True)
113+
return_code = 0 if reply['content']['status'] == 'ok' else 1
114+
if return_code:
115+
raise Exception("jupyter-run error running '%s'" % filename)
116+
else:
117+
code = sys.stdin.read()
118+
reply = self.kernel_client.execute(code, reply=True)
119+
return_code = 0 if reply['content']['status'] == 'ok' else 1
120+
if return_code:
121+
raise Exception("jupyter-run error running 'stdin'")
115122

116123
main = launch_new_instance = RunApp.launch_instance
117124

0 commit comments

Comments
 (0)