How to copy some variables from one notebook to another using different kernel?

As a simple solution, you could use CloudPut, CloudGet and CloudObject.

list = RandomReal[1,10];
CloudPut[list, "myRandomList"]

Then in the other kernel:

CloudGet["myRandomList"]

You need to be signed in to the same Wolfram account from both locations.


As a more direct method, you could establish a MathLink (WSTP) connection between the two kernels. This method is much more fickle, and not very tolerant to user mistakes. It also requires that the two computers be able to see each other over the network and be allowed to communicate over the ports mentioned in the link name.

Here's a short example:

enter image description here

In kernel 1,

link = LinkCreate[LinkProtocol -> "TCPIP"]

Now First[link] will give you the link name as a string. You will need this for the other kernel.

The following call will block until the connection has been established successfully.

LinkActivate[link]

Now in kernel 2,

link = LinkConnect[linkName, LinkProtocol -> "TCPIP"]

linkName is what you got from kernel 1. It consists of port1@ip,port2@ip. Make sure that the IP address is written in a format that can be used on this second computer to reach the first (i.e. not 127.0.0.1).

LinkActivate[link]

At this point, the LinkActivate call should return on kernel 1 as well.

Now you can send data. On one kernel, LinkWrite[link, data], then on the other kernel, LinkRead[link].

Reference:

  • Using WSTP to Communicate between Wolfram System Sessions

You could encode data into an Image:

(* NOTEBOOK 1 *)

encode = Image[{ToCharacterCode @ Compress @ #}, ImageSize -> {100, 100}] &;

testData = ExampleData[{"Text", "DeclarationOfIndependence"}];

encode[testData]   (* copy apparently blank output image *)


(* NOTEBOOK 2 *)

decode = Uncompress @ FromCharacterCode @ First @ Round @ ImageData @ # &;

(* paste image *) // decode

When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume, among the Powers ...