|
Running OS Commands and Hot-Swapping Programs |
Sheerpower's pass statement allows a program to execute
external operating system commands. This provides a direct bridge
between your application and the host environment, enabling tasks
such as invoking utilities, generating files, and integrating with
system-level workflows.
The pass statement accepts a string expression
representing a shell command. The command is executed by the
operating system. When execution completes, the special variable
_integer contains the command's exit status.
This example writes a directory listing to a file named
listing.txt.
The pass statement supports the nowait
modifier.
NOWAIT: Executes the command asynchronously and immediately returns control to the program.
This launches the Windows calculator while allowing the current program to continue execution without blocking.
This example uses the Windows tasklist utility to
retrieve running Chrome processes, writes the results to a CSV
file, and loads the data into a Sheerpower cluster.
The pass statement also supports the
noreturn modifier.
NORETURN: Launches a command and then immediately terminates the current Sheerpower program without waiting for the new process to complete.
This is particularly useful for controlled restarts and hot-swap deployments, where a running system transitions to a new version without downtime.
Problem:
Long-running applications may need to update themselves without
interrupting service or requiring manual restarts.
Solution:
Use pass noreturn: to launch the updated program
instance and immediately exit the current process.
Efficiency:
The existing instance continues operating until the replacement
is ready, enabling seamless transition without blocking or
resource contention.
Takeaway:
pass noreturn: enables clean, deterministic
self-restart behavior for production systems.
Problem:
File paths for generated output can become inconsistent across
environments.
Solution:
Use filespec$("@filename") to anchor output files to
the program's execution directory.
Efficiency:
Eliminates hard-coded paths and reduces deployment friction
across systems.
Takeaway:
The @ prefix ensures predictable file placement
relative to the running program.
Summary:
The pass statement connects Sheerpower programs
directly to the operating system. With support for synchronous
execution, background processing (nowait), and
controlled termination (noreturn), it provides a
flexible and powerful mechanism for system integration and
deployment workflows.
|
Hide Description
|
|
|
Enter or modify the code below, and then click on RUN |
|
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |