(current-seconds
)
returns the current time in seconds. This time
is always an exact integer based on a platform-specific starting date
(with a platform-specific minimum and maximum value).
The value of (
increases as time passes
(increasing by 1 for each second that passes). The current time in
seconds can be compared with a time returned by
current-seconds
)
(see section 11.3.2).file-or-directory-modify-seconds
(seconds->date
secs-n
)
takes secs-n
, a platform-specific
time in seconds (an exact integer) returned by
current-seconds
or
file-or-directory-modify-seconds
, and returns an instance
of the date
structure type, which has the following fields:
time-zone-offset
: the number of seconds east of
GMT for this time zone (e.g., Pacific Standard Time
is -28800
), an exact integer
36
All fields of the date
structure type are accessible by all
inspectors (see section 4.5).
The value returned by current-seconds
or
file-or-directory-modify-seconds
is not portable among
platforms. Convert a time in seconds using
when
portability is needed.seconds->date
See also Chapter 11 in PLT MzLib: Libraries Manual for additional date utilities.
(current-milliseconds
)
returns the current ``time'' in fixnum
milliseconds. This time is based on a platform-specific starting date
or on the machine's startup time. Since the result is a fixnum, the
value is only strictly increasing for a limited (though reasonably
long) time.
(current-process-milliseconds
)
returns the amount of processor
time in fixnum milliseconds that has been consumed by the MzScheme
process on the underlying operaying system. (Under Unix and Mac OS X, this
includes both user and system time.) The precision of the result is
platform-specific, and since the result is a fixnum, the value is
only strictly increasing for a limited (though reasonably long) time.
(current-gc-milliseconds
)
returns the amount of processor time
that has been consumed by MzScheme's garbage collection so far in
fixnum milliseconds. This time is a portion of the time reported by
(
.current-process-milliseconds
)
The
procedure collects timing information for a
procedure application:
time-apply
(time-apply
proc arg-list
)
invokes the procedure proc
with the arguments in arg-list
. Four values are returned: a
list containing the result(s) of applying proc
, the number of
milliseconds of CPU time required to obtain this result, the number
of ``real'' milliseconds required for the result, and the number of
milliseconds of CPU time (included in the second result) spent on
garbage collection.
The reliability of the timing numbers depends on the platform; see section 15.1.2 for more information on time accounting. If multiple MzScheme threads are running, then the reported time may include work performed by other threads.
The time
syntactic form reports timing information
directly to the current output port:
(time
times the evaluation of expr
)expr
,
printing timing information to the current output port. The result of
the
expression is the result of time
expr
.
(subprocess
stdout-output-port stdin-input-port
stderr-output-port command-path arg-string
···)
creates a new process in
the underlying operating system to execute command-path
asynchronously. The command-path
argument is a path to a
program executable, and the arg-string
s are command-line
arguments for the program.
Under Mac OS Classic, arguments are not supported. However, a single
arg-string
argument triggers a hack specific to Mac OS Classic; in
that case, command-path
must be
"by-id"
and the arg-string
argument is a four-character string
specifying an application ID, which is used to find the application
instead of an executable path.
Under Windows, the first arg-string
can be 'exact
,
which triggers a Windows-specific hack: the second arg-string
is used exactly as the command-line for the subprocess, and no
additional arg-string
s can be supplied. Otherwise, a
command-line string is constructed from command-path
and
arg-string
so that a typical Windows console application can
parse it back to an array of arguments.37 If 'exact
is
provided on a non-Windows platform, the
exn:application:mismatch
exception is raised.
Unless it is #f
, stdout-output-port
is used for the
launched process's standard output, stdin-input-port
is used
for the process's standard input, and stderr-output-port
is
used for the process's standard error. All provided ports must be
file-stream ports. Any of the ports can be #f
, in which case
a system pipe is created and returned by
. For
each port that is provided, no pipe is created and the corresponding
returned value is subprocess
#f
.
The
procedure returns four values:
subprocess
a subprocess value representing the create process;
an input port piped from the process's standard output, or
#f
if stdout-output-port
was a port;
an output port piped to the process standard input, or
#f
if stdin-input-port
was a port;
an input port piped from the process's standard error, or
#f
if stderr-output-port
was a port.
Important: All ports returned from
must be
explicitly closed with subprocess
and
close-input-port
.close-output-port
The returned ports are placed into the management of the current
custodian (see section 9.2). The exn:misc
exception is raised when a
low-level error prevents the spawning of a process or the creation of
operating system pipes for process communication.
A subprocess value can be used to obtain further information about the process:
(subprocess-wait
subprocess
)
blocks until the process
terminates, then returns void.
(subprocess-status
subprocess
)
returns
'running
if the process is still running, or its exit
code otherwise. The exit code is an exact integer, and 0
typically indicates success. If the process terminated due to a fault
or signal, the exit code is non-zero.
(subprocess-kill
subprocess force?
)
terminates the
subprocess if force?
is true and if the process still
running, then returns void. If an error occurs during termination,
the exn:misc
exception is raised.
If force?
is #f
under Unix and Mac OS X, the subprocess is
sent an interrupt signal instead of a kill signal (and the subprocess
might handle the signal without terminating). Under Windows, no
action is taken when force?
is #f
.
(subprocess-pid
subprocess
)
returns the operating system's
numerical ID for the process (if any), valid only as long as the
process is running. The ID is an exact integer. Under Mac OS Classic, the
reported ID is always 0
.
(subprocess?
v
)
returns #t
if v
is a
subprocess value, #f
otherwise.
MzLib provides procedures for executing shell commands (as opposed to directly executing a program); see Chapter 24 in PLT MzLib: Libraries Manual for details.
(shell-execute
verb-string target-string parameters-string dir-path show-mode-symbol
)
performs the action specified by verb-string
on target-string
in Windows. For example,
(shell-execute
#f "http://www.plt-scheme.org" "" (current-directory
) 'SW_SHOWNORMAL)
opens the PLT Scheme home page in a browser window. For platforms
other than Windows, the exn:misc:unsupported
exception is raised.
The verb-string
can be #f
, in which case the operating
system will use a default verb. Common verbs include "open"
,
"edit"
, "find"
, "explore"
, and
"print"
.
The target-string
is the target for the action, usually a
filename path. The file could be executable, or it could be a file
with a recognized extension that can be handled by an installed
application.
The parameters-string
argument is passed on to the system to
perform the action. For example, in the case of opening an
executable, the parameters-string
is used as the command line
(after the executable name).
The dir-path
is used as the current directory when performing
the action.
The show-mode-symbol
sets the display mode for an Window
affected by the action. It must be one of the follwoing symbols; the
description of each symbol's meaning is taken from the Windows API
documentation.
'SW_HIDE
-- Hides the window and activates another window.
'SW_MAXIMIZE
-- Maximizes the window.
'SW_MINIMIZE
-- Minimizes the window and
activates the next top-level window in the z-order.
'SW_RESTORE
-- Activates and displays the
window. If the window is minimized or maximized, Windows restores it
to its original size and position.
'SW_SHOW
-- Activates the window and displays it
in its current size and position.
'SW_SHOWDEFAULT
-- Uses a default.
'SW_SHOWMAXIMIZED
-- Activates the window and
displays it as a maximized window.
'SW_SHOWMINIMIZED
-- Activates the window and
displays it as a minimized window.
'SW_SHOWMINNOACTIVE
-- Displays the window as a
minimized window. The active window remains active.
'SW_SHOWNA
-- Displays the window in its current
state. The active window remains active.
'SW_SHOWNOACTIVATE
-- Displays a window in its
most recent size and position. The active window remains active.
'SW_SHOWNORMAL
-- Activates and displays a
window. If the window is minimized or maximized, Windows restores it
to its original size and position.
If the action fails, the exn:misc
exception is raised. If the action succeeds,
the result is either a subprocess value (see section 15.2) or
#f
if the operating system did not return a process handle
on success. If a subprocess value is returned, its process ID is
0
, instead of the real process ID.
(getenv
name-string
)
gets the value of an operating system
environment variable. The name-string
argument cannot contain a
null character; if an environment variable named by name-string
exists, its value is returned (as a string); otherwise, #f
is
returned.
(putenv
name-string value-string
)
sets the value of an operating
system environment variable. The name-string
and
value-string
arguments are strings that cannot contain a null
character; the environment variable named by name-string
is set
to value-string
. The return value is #t
if the
assignment succeeds, #f
otherwise.
Although Mac OS Classic does not have operating system environment
variables,
returns values installed with
getenv
(which always succeeds) in the same MzScheme session.
When MzScheme is started, an initial environment is read from an
Environment file in the current directory if it exists. An
Environment file must contain a sequence of two-item lists
where the putenv
name
string is the first item in the list and the
value
string is the second. For example, an Environment
file might contain the following:
("PLTCOLLECTS" ";My Disk:Extra Collections:") ("USER" "joeuser")
(system-type
[details?
])
returns a symbol indicating the type of
the operating system for a running MzScheme if details?
is
#f
or not provided. The possible values are:
Future ports of MzScheme will expand this list of system types. If
details?
is not #f
, then the result is a string, which
contains further details about the operating system and the current
machine in a platform-specific format.
(system-library-subpath
)
returns a relative directory pathname
string. This string can be used to build pathnames to system-specific
files. For example, when MzScheme is running under Solaris on a Sparc
architecture, the subpath is "sparc-solaris"
, while the subpath
for Windows on an Intel architecture is
"win32\\i386"
.
(version
)
returns an immutable string indicating the currently
executing version of MzScheme.
(banner
)
returns an immutable string for MzScheme's start-up
banner text (or the banner text for an embedding program, such as
MrEd). The banner string ends with a newline.
36 The value produced for the time-zone-offset
field
tends to be sensitive to the value of the "TZ"
environment variable, especially on Unix
platforms. Consult the system documentation (usually
under tzset) for details.
37 For information on the Windows command-line conventions, search for ``command line parsing'' at http://msdn.microsoft.com/.