Logo-small

6.42 OSProcess

Execute command line scripts with OSProcess and CommandShell.

If you don't care about the output, you can use the OSProcess class as follows:

  OSProcess command: 'touch file.txt'.

If you want access to the output, use PipeableOSProcess (from the CommandShell project) instead. For example:

  (PipeableOSProcess command: 'pwd') output.

Output can also be treated as a stream (see the 'streaming' protocol). For example:

  • #upToEnd - immediately return with whatever output is available
  • #errorUpToEnd - same for stderr

Both classes have both #command:, which immediately returns an object representing the running process object, and #waitForCommand:, which will allow the process to complete before returning.

To access the environment variables associated with the VM process, evaluate:

  OSProcess thisOSProcess environment

To load OSProcess:

  Gofer new
squeaksource: 'OSProcess';
package: 'OSProcess';
load.

To load CommandShell, you can start with:

  Gofer new
squeaksource: 'CommandShell';
package: 'CommandShell-Piping';
load.

Add a Note

Licensed under Creative Commons BY-NC-SA | Published using Pier |