7
$\begingroup$

If I type the following

enter image description here

Mathematica returns nothing. Requesting Information[%] seems to indicate that the operation $Failed. I have looked at the messages window and in the terminal window, but nothing seems to be output?

$\endgroup$
3
  • $\begingroup$ What are you expecting to see? console.log does not return the string that it logged in javascript (it returns undefined), so running the code would not return something (eg, nothing would be displayed in the notebook). Do you want behaviour like Echo or Print? $\endgroup$
    – Carl Lange
    Jun 11, 2019 at 18:25
  • 2
    $\begingroup$ After some checking, my belief is that there is no easy way to have console.log do something like Echo or Print. The main problem here is that console.log is built to have a side effect - writing to the equivalent of 'stdout' - and that stream isn't a thing you can access from the notebook interface. console.log doesn't return anything, and so, you don't see output. $\endgroup$
    – Carl Lange
    Jun 11, 2019 at 18:40
  • $\begingroup$ Thx, I was away for the summer. Yes I think you are right. I was hoping to get some output from the console.log. I am happy to accept your comment as an Answer $\endgroup$
    – ulysseus
    Sep 5, 2019 at 11:30

2 Answers 2

3
$\begingroup$

After some checking, my belief is that there is no easy way to have console.log do something like Echo or Print. The main problem here is that console.log is built to have a side effect - writing to the equivalent of 'stdout' - and that stream isn't a thing you can access from the notebook interface. console.log doesn't return anything, and so, you don't see output.

Edit: According to M.R.'s answer, this now works in 12.1. 👍👍

$\endgroup$
4
  • $\begingroup$ Any chance to redirect console.log to stdout? $\endgroup$
    – b3m2a1
    Sep 7, 2019 at 21:15
  • $\begingroup$ I checked this and it turns out console.log actually does write to stdout, but for some reason it's not picked up by the notebook. process.stdout.write also doesn't get caught by the notebook. $\endgroup$
    – Carl Lange
    Sep 8, 2019 at 11:49
  • $\begingroup$ interesting. It seems one would have to check where the ZMQ socket is connecting to in the NodeJS case on the Mathematica side to figure out where things need to be written. $\endgroup$
    – b3m2a1
    Sep 8, 2019 at 18:19
  • $\begingroup$ I wonder if print in Python gets caught, and if so, how. $\endgroup$
    – Carl Lange
    Sep 9, 2019 at 7:38
2
$\begingroup$

Console log seems to work (emits cells of type Print) in version 12.1:

enter image description here

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.