Popup YouTube Video
Sheerpower Logo

Running OS Commands and Hot-Swapping Programs


Introduction

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.

Basic Usage

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.

pass "exit 9" print 'exit status was '; _integer

This example writes a directory listing to a file named listing.txt.

pass "dir > listing.txt"

Optional NOWAIT Feature

The pass statement supports the nowait modifier.

NOWAIT: Executes the command asynchronously and immediately returns control to the program.

pass nowait: "calc"

This launches the Windows calculator while allowing the current program to continue execution without blocking.

Real-World Example: Exporting Chrome Processes to CSV

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.

cluster tasks: image$, pid$, session_name$, session_nbr, memk$ output_file$ = filespec$("@chrome.csv") cmd$ = 'tasklist /fi "imagename eq chrome.exe" /fo csv > ' + output_file$ pass cmd$ cluster input name output_file$, headers 1: tasks print 'Here are the CHROME processes' print cluster tasks: all

Optional NORETURN Feature

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.

!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! c h e c k _ n e w _ c o d e !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% routine check_new_code: private this_program$, last_datetime$, change_phase$ ask system: program this_program$ select case change_phase$ case '' z0$ = fileinfo$(this_program$, 'revision_date') if last_datetime$ = '' then last_datetime$ = z0$ exit routine end if if last_datetime$ = z0$ then exit routine change_phase$ = 'waiting_for_new_code' case 'waiting_for_new_code' when exception in open file temp_ch: name this_program$, lock close #temp_ch change_phase$ = 'restart' use end when case 'restart' pass noreturn: this_program$ end select end routine

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.