vatlab/jupyterlab-sos

`%cd` magic does not work

gaow opened this issue · 7 comments

gaow commented

Is this the pending PR request will address, or can be fixed without upstream changes?

2018-05-08-11-44-30_scrot

%cd does not change the current directory of a running kernel so it needs to be executed before the kernel is started.

I could not find a way to change current directory of a running process.

But when I think of this problem now, I think we can define a command for each kernel and execute it silently to change directory with the %cd magic.

gaow commented

So this is indeed specific to JupyterLab and related to the PR? Because back in SoS notebook:

2018-05-08-12-08-10_scrot

and I've been relying on this feature to keep my notebook out of the dir with messy output data files.

No. If you start a subkernel before you use %cd, %cd does not apply to the subkernel.

This should be the same for JLab and Jupyter Notebook.

  • sos: os.chdir(os.path.expanduser(to_dir))
  • python2/python3: the same
  • R: setwd(dir)
  • matlab: cd dir
  • node/javascript: process.chdir('/tmp');
  • bash: cd dir
  • SAS: x 'cd <full path>'; (according to here)
  • julia: cd("/")

A potential problem is that dir might be given in a format that is not acceptable to some of the kernels.

From Jupyter Notebook, not lab

  1. cd before kernel starts

image

  1. cd after kernel starts

image

Fixed.

image