I've written this script in the ~/.bashrc file and I've sourced the file, but it's not working properly. It's purpose is to open the link provided by the jupyter notebook in the Chrome browser in a new tab.

        echo $1 # <--- shows that jupfire is sending an empty string
        # I'm using Windows Subsystem for Linux
        "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" $1

        jupyter notebook 2>juptemp &
        sleep 3
        chrome "$(tail -1 juptemp | grep http)"
        rm juptemp

After searching and trying some unsuccessful ways, I've come to the conclusion that it has something to do with I/O buffering. Probably the "&" after the first line of "jupfire" function causes the stderr to not be flushed into juptemp, and thus an empty string is sent to the chrome function.

It seems that I should use "stdbuf" but I have no idea how, by checking the manual page, I came up with this: stdbuf -e0 jupyter notebook 2>juptemp & as the first line of the jupfire function, but it's still not working.(to be clear, by "not working" I mean it's opening a new tab in chrome browser with its address bar being empty). If the problem is with buffering, could you guide me use the flushing in the proper way? thanks.

Edit: This is a sample output of the command "jupyter notebook":

To access the notebook, open this file in a browser:
Or copy and paste one of these URLs:
  • What is the contents of juptemp? What output does jupyter notebook provide? Your chrome function is being executed immediately after jupyter notebook starts which may not be enough time for it to start writing output to juptemp – Jesse_b Jul 10 at 21:51
  • @Jesse_b I've edited the question to consider these. – aderchox Jul 10 at 21:57
  • 1
    So you probably have to wait for the command to run longer before the file contains any output. Have you run the command normally and observed how long it takes to output? – Jesse_b Jul 10 at 22:22
  • 2
    @Jesse_b Oh thanks! Yes this was the problem :(. Thanks for your help. It's working fine now. – aderchox Jul 10 at 22:27
  • 2
    Can @Jesse_b post his answer and then aderchox accept it? – Jonas Berlin Jul 11 at 9:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.