Skip to content

Commit cdedd2d

Browse files
authored
Document return of exit codes (#852)
2 parents 8a4b048 + 38d41eb commit cdedd2d

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

PACKAGING.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,40 @@ $ fpm run
128128
pi = 3.14159274
129129
```
130130

131+
Although we have named our program `hello`, which is the same name as the
132+
package name in `fpm.toml`, you can name it anything you want as long as it’s
133+
permitted by the language.
134+
131135
Notice that you can run `fpm run`, and if the package hasn’t been built yet,
132136
`fpm build` will run automatically for you. This is true if the source files
133137
have been updated since the last build. Thus, if you want to run your
134138
application, you can skip the `fpm build` step, and go straight to `fpm run`.
135139

136-
Although we have named our program `hello`, which is the same name as the
137-
package name in `fpm.toml`, you can name it anything you want as long as it’s
138-
permitted by the language.
140+
When running your application using `fpm run`, the program's exit code is
141+
passed by *fpm* back to the operating system. So, it is possible to use Fortran
142+
numbered `stop` and `error stop` codes to pass termination reasons back to the terminal.
143+
144+
Try running the following app with `fpm run`:
145+
146+
```fortran
147+
program main
148+
use math_constants, only: pi
149+
150+
real :: angle
151+
152+
read(*,*,iostat=ierr) angle
153+
if (ierr/=0) then
154+
stop 2 ! Not real
155+
elseif (angle>pi) then
156+
stop 1
157+
else
158+
stop 0
159+
endif
160+
end program main
161+
```
162+
163+
and then checking that the error code matches. Note that error codes are passed to variable `$?`
164+
on Unix/Mac systems, and to environment variable `%errorlevel%` on Windows.
139165

140166
In this last example, our source file defined a `math_constants` module inside
141167
the same source file as the main program. Let’s see how we can define an *fpm*

0 commit comments

Comments
 (0)