Skip to content

demarey/SubProcess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SubProcess Build Status

This project allows to run OS sub processes from a Pharo image. It uses GLib IO library to spawn processes through FFI calls. SubProcess offers a high-level API, OS-agnostic API to run easily processes from your Pharo code. Windows, Linux and Mac Os are supported!

WARNING: For now, there is only support for synchroneous processes (i.e. the execution will wait the spawed process termination). Asynchroneous support will come a bit later. WARNING 2: fetching of the exit code may not be reliable (TO FIX!)

Examples

Run a simple command

process := SPSProcessConfiguration new
  command: '/bin/ls';
  sync.
process run.
process := SPSProcessConfiguration new
  command: 'C:\Windows\System32\systeminfo.exe';
  sync.
process run.

Run a command and getting the output

process := SPSProcessConfiguration new
  command: '/bin/ls';
  sync.
process run.
  
out := process stdOut.
err := process stdErr.

Set the working directory

process := SPSProcessConfiguration new
  workingDirectory: '/etc';
  command: '/bin/ls';
  sync.
	
process run.

Give arguments

process := SPSProcessConfiguration new
  command: '/bin/ls';
  arguments: #('/etc');
  sync.
	
process run.

Use a shell to run the command

process := SPSProcessConfiguration new
  workingDirectory: 'C:\';
  windowsShellCommand;
  addArgument: 'dir';
  sync.
  
process run.

Getting the status of the process

Know if the process has completed its execution

process := SPSProcessConfiguration new
  command: '/bin/ls';
  sync.
process run.
self assert: process isComplete.

Know if the spawn of the process is sucessful (no error)

process := SPSProcessConfiguration new
  command: '/bin/ls';
  sync.
process run.
self assert: process isSuccess.

Getting error if the spawn of the process failed

process := SPSProcessConfiguration new
  command: '/bin/ls';
  sync.
[ process run ]
on: SPSError
do: [ :error | error messageText inspect ]

Encoding

When running a command that will give you back some output (standard output or standard error), you will get an encoded String (a byte array) that needs to be decoded. SubProcess cannot guess what will be the encoding as many encodings are used worldwide. One commonly used encoding is utf-8 on unix-like systems. On Windows, different encondings are used. SubProcess configure a default encoding (utf-8 on unix-like systems and cp-850 on Windows) for convenience. Do not forget you could need a different encoding. If so, you can configure it before running the process:

process := SPSProcessConfiguration new
  encoding: 'ISO-8859-2'
  command: '/bin/ls';
  sync.
process run.
out := process stdOut.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published