Calling Subsidiary Wolfram System Processes
start an external program and open a connection to it
The basic way that the various different objects involved in a Wolfram System session are kept organized is by using Wolfram Symbolic Transfer Protocol (WSTP) packets. A WSTP packet is simply an expression with a definite head that indicates its role or meaning.
text to enter corresponding to an input line
text returned corresponding to an output line
text returned for the name of an input line
text returned for the name of an output line
The fact that LinkRead returns an InputNamePacket indicates that the subsidiary Wolfram System is now ready for new input:
This enters two Print commands as input:
Here is the text from the first Print:
And here is the text from the second Print:
No output line is generated, so the new packet is an InputNamePacket:
text from Print etc.
a message name
parts of PostScript graphics
the end of PostScript graphics
If you enter input to the Wolfram Language using EnterTextPacket["input"], then the Wolfram Language will automatically generate a string version of your output and will respond with ReturnTextPacket["output"]. But if you instead enter input using EnterExpressionPacket[expr], then the Wolfram Language will respond with ReturnExpressionPacket[expr] and will not turn your output into a string.
an expression to enter corresponding to an input line
an expression returned corresponding to an output line
InputNamePacket and OutputNamePacket packets are often convenient for making it possible to tell the current state of a subsidiary Wolfram System session. But you can suppress the generation of these packets by calling the subsidiary Wolfram System session with a string such as "math -mathlink -batchoutput".
Even if you suppress the explicit generation of InputNamePacket and OutputNamePacket packets, the Wolfram System will still process any input that you give with EnterTextPacket or EnterExpressionPacket as if you were entering an input line. This means for example that the Wolfram Language will call $Pre and $Post, and will assign values to In[$Line] and Out[$Line].
an expression to be sent purely for evaluation
an expression returned from an evaluation
The result is a pure ReturnPacket:
After that, the actual result of the Print is returned:
In most cases, it is reasonable to assume that sending an EvaluatePacket to the Wolfram System will simply cause the Wolfram System to do a computation and to return various other packets, ending with a ReturnPacket. However, if the computation involves a function like Input, then the Wolfram System will have to request additional input before it can proceed with the computation.
This sends a packet whose evaluation involves an Input function:
What comes back is an InputPacket, which indicates that further input is required:
send an interrupt to a WSTP‐compatible program