Wolfram Language & System 10.3 (2015)|Legacy Documentation

This is documentation for an earlier version of the Wolfram Language.View current documentation (Version 11.2)

Calling Subsidiary Wolfram System Processes

LinkLaunch["prog"]start an external program and open a connection to it

Connecting to a subsidiary program via WSTP.

This starts a subsidiary Wolfram System process on the computer system used here.
Here is a packet representing the first input prompt from the subsidiary Wolfram System process.
This writes a packet representing text to enter in the subsidiary process.
Click for copyable input
Here is a packet representing the output prompt from the subsidiary process.
And here is the actual result from the computation.

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.

EnterTextPacket["input"]text to enter corresponding to an input line
ReturnTextPacket["output"]text returned corresponding to an output line
InputNamePacket["name"]text returned for the name of an input line
OutputNamePacket["name"]text returned for the name of an output line

Basic packets used in Wolfram System sessions.

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.
Click for copyable 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.
TextPacket["string"]text from Print etc.
MessagePacket[symb,"tag"]a message name
DisplayPacket["string"]parts of PostScript graphics
DisplayEndPacket["string"]the end of PostScript graphics

Some additional packets generated in Wolfram System sessions.

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.

EnterExpressionPacket[expr]an expression to enter corresponding to an input line
ReturnExpressionPacket[expr]an expression returned corresponding to an output line

Packets for representing input and output lines using expressions.

This enters an expression into the subsidiary Wolfram System session without evaluating it.
Click for copyable input
Here are the next 3 packets that come back from the subsidiary Wolfram System session.
Click for copyable input

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 .

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].

EvaluatePacket[expr]an expression to be sent purely for evaluation
ReturnPacket[expr]an expression returned from an evaluation

Evaluating expressions without explicit input and output lines.

This sends an EvaluatePacket. The Unevaluated prevents evaluation before the packet is sent.
Click for copyable input
The result is a pure ReturnPacket.
Click for copyable input
This sends an EvaluatePacket requesting evaluation of Print[x].
Click for copyable input
The first packet to come back is a TextPacket representing text generated by the Print.
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.
Click for copyable input
What comes back is an InputPacket, which indicates that further input is required.
There is nothing more to be read on the link at this point.
This enters more input.
Click for copyable input
Now the Input function can be evaluated, and a ReturnPacket is generated.
LinkInterrupt[link]send an interrupt to a WSTPcompatible program

Interrupting a WSTP-compatible program.

This sends a very timeconsuming calculation to the subsidiary process.
Click for copyable input
The calculation is still going on.
This sends an interrupt.
Click for copyable input
Now the subsidiary process has stopped and is sending back an interrupt menu.
This closes the link.
Click for copyable input