Run a program with CommandShell
Jump to navigation
Jump to search
- SUPER GOTCHA. PipeableOSProcess is extremely handy, but also, extremely dangerous. Remember to close the pipes after using it, as shown in the examples below, or sooner or later your program will crash. Keep checked your open pipes with
$> sudo lsof | grep squeak | grep pipe
. - SUPER GOTCHA. I have very bad surprises running PipeableOSProcess in a secondary process. If you kill the process and a PipeableOSProcess is running you may loose control of the image. If found OSProcess to be more resilient so I recommend you use that, even if it is more wordy to control.
Feature require: 'CommandShell'.
Problem. I want to know how much free space I still have in my disks. This is half done
if I know that in Linux I can get that info with df -h
.
- Solution-1. This is the easiest solution.
- +] Quite short to type in
- +/-] It is synchronous with your code. This can be good and bad. When this commands end, the commands after it get executed. For the bad part read on.
- -] It your program to run takes a long time your Cuis is going to lock untill it has finished.
- NOTE. This example uses a new interface functions introduced in 2021.
p _ PipeableOSProcess waitForCommand: 'uname -a ' . p exitCode . "=> 0 " p outputAndError . "=> #('Linux deb4 5.10.0-9-amd64 #1 SMP Debian 5.10.70-1 (2021-09-30) x86_64 GNU/Linux ' '') " p closePipes. p close.
- Solution-2. As before but async
- +] This way does not lock you system
- -] You must check when execution ends yourself
p _ PipeableOSProcess command: 'df -h'. out _ p output . " store the output somewhere, you can do it only once. " p processProxy pid. "=> 112011 " p processProxy exitCode. "=> 0 " p closePipes. p close. out. "Ctrl+p, see the output" "=> 'Filesystem Size Used Avail Use% Mounted on udev 5.1G 0 5.1G 0% /dev tmpfs 1.1G 18M 1.1G 2% /run /dev/sda2 93G 80G 8.1G 91% / tmpfs 5.2G 745M 4.4G 15% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 5.2G 0 5.2G 0% /sys/fs/cgroup /dev/sda1 511M 3.3M 508M 1% /boot/efi //nas.borghi.lan/sambaDisk/DiscoS/ 5.5T 3.8T 1.7T 70% /mnt/discoR //backup.borghi.lan/backupDisk/ 22T 7.1T 15T 34% /mnt/discoBackup tmpfs 1.1G 28K 1.1G 1% /run/user/1000 vmhgfs-fuse 1.9T 588G 1.3T 32% /mnt/macos vmhgfs-fuse 1.9T 588G 1.3T 32% /mnt/dropbox ' "
Exercise-1. Get your Linux kernel version. Google around to discover the appropriate shell command.
Exercise-2. Inspect the content of variable p
, you will see other interesting stuff there.
NM 06-Sep-2021. Cuis version...