-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathProcessExample.hs
More file actions
38 lines (33 loc) · 965 Bytes
/
ProcessExample.hs
File metadata and controls
38 lines (33 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Main where
import Control.Monad (unless)
import SDL3
import System.Exit (exitFailure, exitSuccess)
main :: IO ()
main = do
-- Initialize SDL
initSuccess <- sdlInit []
unless initSuccess $ do
sdlLog "Failed to initialize SDL!"
exitFailure
-- Create a process to run 'ls' (or 'dir' on Windows)
let args = ["ls", "-l"] -- Use "dir" on Windows
process <- sdlCreateProcess args True -- Pipe stdio
case process of
Nothing -> do
sdlLog "Failed to create process!"
sdlQuit
exitFailure
Just proc -> do
-- Read process output
output <- sdlReadProcess proc
case output of
Nothing -> sdlLog "Failed to read process output!"
Just (out, exitcode) -> do
sdlLog $ "Process output:\n" ++ out
sdlLog $ "Exit code: " ++ show exitcode
-- Clean up
sdlDestroyProcess proc
-- Shutdown SDL
sdlQuit
sdlLog "Application terminated successfully"
exitSuccess