diff options
| author | Omar Rizwan <omar@omar.website> | 2022-12-01 20:12:31 +0000 |
|---|---|---|
| committer | Omar Rizwan <omar@omar.website> | 2022-12-01 20:12:31 +0000 |
| commit | 4de4988bd960e0bb676731ffe0168b57ff21cfb0 (patch) | |
| tree | 481166620253db3bc08f2a27685f151c7b942bbd /virtual-programs | |
| parent | New programs (diff) | |
| download | folk-4de4988bd960e0bb676731ffe0168b57ff21cfb0.tar.gz folk-4de4988bd960e0bb676731ffe0168b57ff21cfb0.zip | |
Async Unix commands program
Diffstat (limited to 'virtual-programs')
| -rw-r--r-- | virtual-programs/unix-commands.folk | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/virtual-programs/unix-commands.folk b/virtual-programs/unix-commands.folk new file mode 100644 index 00000000..9958debb --- /dev/null +++ b/virtual-programs/unix-commands.folk @@ -0,0 +1,33 @@ +Wish $this has filename "unix-commands.folk" + +set ::unixjobs [dict create] +set ::nextunixjobid 0 +proc ::readline {jobid channel} { + if {[gets $channel line] >= 0} { + dict with ::unixjobs $jobid { + lappend log $line + Retract $object is running Unix command $command with job id $jobid output /something/ + Assert $object is running Unix command $command with job id $jobid output $log + Step + } + } elseif {[eof $channel]} { + close $channel + } +} + +When /someone/ wishes /p/ runs Unix command /c/ { + set jobid [incr ::nextunixjobid] + dict set ::unixjobs $jobid [dict create object $p command $c log [list]] + + lassign [chan pipe] reader writer + set pid [exec {*}$c >@$writer 2>@1 &] + close $writer + + fconfigure $reader -blocking 0 + fileevent $reader readable [list ::readline $jobid $reader] + + + When /p/ is running Unix command /c/ with job id $jobid output /log/ { + Wish $p is labelled [join $log "\n"] + } +}
\ No newline at end of file |
