ProcessConnection

From Fernseher
Jump to navigationJump to search

ProcessConnection is a class to represent an external process running on the server that is started by this Modjs script and runs independently. It can be read and written to as well.

Start the process by creating a new ProcessConnection:

process = new ProcessConnection(cmd, args array)
process = new ProcessConnection(cmdandargs)
process = new ProcessConnection(File, args array)

Read and write just like for TCPConnections:

process.send(string | array of strings)
string = process.recvAll()
string = process.recvLine(chomp?)
array of strings = process.recvLines(numlines, chomp?)
bool = process.dataAvailable()

Closing the process can be done by garbage collection or explicit close():

status = process.close()

Note that close() blocks until the process ends and a status is returned. Garbage collection will do the same.

To send a signal to the process (and thus possibly killing it earlier, if needed):

process.signal(signum)

Exceptions can be thrown:

ProcessConnectionOpenError
ProcessConnectionChildClosed