The current working directory from the system. Here we saw commands to change the current working directory and obtain Ghci> setCurrentDirectory "." ghci> getCurrentDirectory Ghci> :module System.Directory ghci> setCurrentDirectory "/etc" Most of these functions are straightforwardĮquivalents to C library calls or shell commands. Let's use ghci toĭemonstrate a few of them. Reference for System.Directory provides aĬomprehensive list of the functions available. You can get a list of files in a directory, rename or delete files,Ĭopy files, change the current working directory, or create newĭirectories. The System.Directory module contains quite a fewįunctions that can be used to obtain information from the filesystem. If you don't want to pass any arguments, you can simplyĬalendartime.ghci modtime.ghci rp.ghci RunProcessSimple.hsĬmd.ghci posixtime.hs rps.ghci timediff.ghciĭir.ghci rawSystem.ghci RunProcess.hs time.ghci Instead, it expects every argument to be contained RawSystem does not parse arguments from a string or Here, we run the equivalent of the shell command ls -l /usr. Ghci> :module System.Cmd ghci> rawSystem "ls" Program, with the specified arguments, and return the exit code from It is possible to invoke external commands from Haskell. Windows does not support POSIX byĭefault, but the Cygwin environment provides a POSIX compatibility layer POSIX is a standard for Unix-like operating systems such as However, we will be focusing on the POSIX environment for much of theĬhapter. In thisĬhapter, we will use generic OS-independent modules as much as possible. Specialized modules exist for different operating systems. Invocation, and some simple tools to handle tasks that might otherwise be We are going to implement piping, easy command "language" that is valid Haskell, implemented in pure Haskell, that makes In this chapter, we are going to attempt something ambitious: a Perl-like To write programs that interface with the operating system at a low level Haskell canĪlso be used for lower-level systems programming. So far, we've been talking mostly about high-level concepts. Table of Contents Running External Programs Directory and File Information Program Termination Dates and Times ClockTime and CalendarTime Using ClockTime Using CalendarTime TimeDiff for ClockTime File Modification Times Extended Example: Piping Using Pipes for Redirection Better Piping Final Words on Pipes
0 Comments
Leave a Reply. |