Commit 89f342ef authored by Mart Lubbers's avatar Mart Lubbers

Add the option to customize the exit code for terminateProcess

On windows this means specifying the error code
On posix this means specifying the kill signal
parent d315c7d3
Pipeline #40591 passed with stage
in 1 minute and 57 seconds
......@@ -130,6 +130,14 @@ writePipe :: !String !WritePipe !*World -> (!MaybeOSError (), !*World)
*/
terminateProcess :: !ProcessHandle !*World -> (!MaybeOSError (), !*World)
/**
* terminates the process if it is still running and releases the process handle resources.
* @param the process handle.
* @param the kill signal number
* @return ()
*/
terminateProcessCode :: !ProcessHandle !Int !*World -> (!MaybeOSError (), !*World)
/**
* closes the IO channels of the process.
* @param the io channels
......
......@@ -404,9 +404,9 @@ writePipe str (WritePipe fd) world
| res == -1 = getLastOSError world
= (Ok (), world)
terminateProcess :: !ProcessHandle !*World -> (!MaybeOSError (), !*World)
terminateProcess pHandle=:{pid} world
# (res, world) = kill pid 15 world // Termination signal
terminateProcessCode :: !ProcessHandle !Int !*World -> (!MaybeOSError (), !*World)
terminateProcessCode pHandle=:{pid} sig world
# (res, world) = kill pid sig world // Termination signal
| res == -1 = getLastOSError world
// otherwise process will remain as zombie
# status = createArray 1 0
......@@ -414,6 +414,9 @@ terminateProcess pHandle=:{pid} world
| res == -1 = getLastOSError world
= (Ok (), world)
terminateProcess :: !ProcessHandle !*World -> (!MaybeOSError (), !*World)
terminateProcess ph w = terminateProcessCode ph 15 w
closeProcessIO :: !ProcessIO !*World -> (!MaybeOSError (), !*World)
closeProcessIO {stdIn = WritePipe fdStdIn, stdOut = ReadPipe fdStdOut, stdErr = ReadPipe fdStdErr} world
# (res, world) = close fdStdIn world
......
......@@ -116,6 +116,14 @@ writePipe :: !String !WritePipe !*World -> (!MaybeOSError (), !*World)
*/
terminateProcess :: !ProcessHandle !*World -> (!MaybeOSError (), !*World)
/**
* terminates the process if it is still running and releases the process handle resources.
* @param the process handle.
* @param the exit code
* @return ()
*/
terminateProcessCode :: !ProcessHandle !Int !*World -> (!MaybeOSError (), !*World)
/**
* closes the IO channels of the process.
* @param the io channels
......
......@@ -196,11 +196,14 @@ writePipe str (WritePipe hPipe) world
| not ok = getLastOSError world
= (Ok (), world)
terminateProcess :: !ProcessHandle !*World -> (!MaybeOSError (), !*World)
terminateProcess hProc=:{processHandle} world
# (ok, world) = 'System._WinBase'.terminateProcess processHandle 0 world
terminateProcessCode :: !ProcessHandle !Int !*World -> (!MaybeOSError (), !*World)
terminateProcess hProc=:{processHandle} exitCode world
# (ok, world) = 'System._WinBase'.terminateProcess processHandle exitCode world
= closeProcessHandle hProc world
terminateProcess :: !ProcessHandle !*World -> (!MaybeOSError (), !*World)
terminateProcess ph w = terminateProcessCode ph 0 w
closeProcessIO :: !ProcessIO !*World -> (!MaybeOSError (), !*World)
closeProcessIO {stdIn = WritePipe hStdIn, stdOut = ReadPipe hStdOut, stdErr = ReadPipe hStdErr} world
# (ok, world) = closeHandle hStdIn world
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment