# Calling Subsidiary *Mathematica* Processes

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

Connecting to a subsidiary program via *MathLink*.

In[1]:= |

Out[1]= |

In[2]:= |

Out[2]= |

In[3]:= |

In[4]:= |

Out[4]= |

In[5]:= |

Out[5]= |

The basic way that the various different objects involved in a *Mathematica* session are kept organized is by using *MathLink* *packets*. A *MathLink* 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 *Mathematica* sessions.

*Mathematica*is now ready for new input.

In[6]:= |

Out[6]= |

In[7]:= |

In[8]:= |

Out[8]= |

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

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 *Mathematica* sessions.

If you enter input to *Mathematica* using EnterTextPacket["input"], then *Mathematica* 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 *Mathematica* 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.

In[11]:= |

In[12]:= |

Out[12]= |

InputNamePacket and OutputNamePacket packets are often convenient for making it possible to tell the current state of a subsidiary *Mathematica* session. But you can suppress the generation of these packets by calling the subsidiary *Mathematica* session with a string such as .

Even if you suppress the explicit generation of InputNamePacket and OutputNamePacket packets, *Mathematica* 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 *Mathematica* 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.

In[13]:= |

In[14]:= |

Out[14]= |

In[15]:= |

In[16]:= |

Out[16]= |

In[17]:= |

Out[17]= |

In most cases, it is reasonable to assume that sending an EvaluatePacket to *Mathematica* will simply cause *Mathematica* to do a computation and to return various other packets, ending with a ReturnPacket. However, if the computation involves a function like Input, then *Mathematica* will have to request additional input before it can proceed with the computation.

In[18]:= |

In[19]:= |

Out[19]= |

In[20]:= |

Out[20]= |

In[21]:= |

In[22]:= |

Out[22]= |

LinkInterrupt[link] | send an interrupt to a MathLink-compatible program |

Interrupting a *MathLink*-compatible program.

In[23]:= |

In[24]:= |

Out[24]= |

In[25]:= |

In[26]:= |

Out[26]= |

In[27]:= |