IPC via named pipe: Difference between revisions

m
syntax highlighting fixup automation
m (→‎{{header|Wren}}: Replace an unnecessary tab.)
m (syntax highlighting fixup automation)
Line 12:
=={{header|C}}==
{{libheader|pthread}}
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
Line 102:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 177:
output.Close()
}
}</langsyntaxhighlight>
 
=={{header|Perl}}==
{{trans|Raku}}
<langsyntaxhighlight Perllang="perl"># 20200924 added Perl programming solution
 
use strict;
Line 214:
}
sleep .5;
}</langsyntaxhighlight>
{{out}}
Terminal 1
Line 241:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\IPC_via_named_pipe.exw
Line 322:
<span style="color: #0000FF;">{}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">call_named_pipe</span><span style="color: #0000FF;">(</span><span style="color: #000000;">szPipename</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"quit"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</langsyntaxhighlight>-->
{{out}}
After letting it run for about 5s before hitting escape, on separate terminal windows:
Line 337:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(call 'mkfifo "in" "out") # Create pipes
 
(zero *Cnt) # Initialize byte counter
Line 356:
 
(push '*Bye '(call 'rm "in" "out")) # Remove pipes upon exit
(wait) # (Terminate with Ctrl-C)</langsyntaxhighlight>
Test:
<pre>$ line <out
Line 368:
 
=={{header|Racket}}==
<langsyntaxhighlight Racketlang="racket">#lang racket
 
(define-values (in out) (make-pipe))
Line 391:
 
(thread-wait t1)
(thread-wait t2)</langsyntaxhighlight>
 
=={{header|Raku}}==
{{incorrect|Raku| Blocks on the read pipe and not able to empty/update the write pipe according to the task requirement }}
Couldn't figure out how to get around the IO blockages as per the talk page so any help would be appreciated, thanks in advance.
<syntaxhighlight lang="raku" perl6line># 20200923 Added Raku programming solution
 
use NativeCall;
Line 429:
}
sleep ½;
}</langsyntaxhighlight>
{{out}}
Terminal 1
Line 459:
{{works with|Unix}}
 
<langsyntaxhighlight lang="ruby">require 'socket'
 
# Ruby has no direct access to mkfifo(2). We use a shell script.
Line 519:
end
end
end</langsyntaxhighlight>
 
Example run:
Line 537:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl"># Make the pipes by calling a subprocess...
exec sh -c {test -p in || mkfifo in || exit 1;test -p out || exec mkfifo out}
 
Line 568:
 
# Run the event loop until done
vwait forever</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 578:
 
This works fine on Ubuntu 20.04 and should work on other Linux distros though I can't vouch for anything else.
<langsyntaxhighlight lang="ecmascript">/* ipc_via_named_pipe.wren */
 
var InputFifo = "in"
Line 631:
 
Fifo.make(InputFifo, 438)
Fifo.make(OutputFifo, 438)</langsyntaxhighlight>
<br>
We now embed this script in the following C program, build and run from one terminal.
<langsyntaxhighlight lang="c">/* gcc ipc_via_named_pipe.c -o ipc_via_named_pipe -lpthread -lwren -lm */
 
#include <stdio.h>
Line 804:
free(script);
return 0;
}</langsyntaxhighlight>
<br>
{{out}}
Line 822:
zkl doesn't open pipes but it knows about them (on Unix anyway as they are just a file). So, outside of the program, create two named pipes and read/write to them inside the program.
{{trans|C}}
<langsyntaxhighlight lang="zkl">pipe:=Thread.Pipe(); // NOT a Unix pipe, for inter-thread commication
fcn writeLoop(pipe){ // a thread
out:=File("out","w");
Line 839:
}.launch(pipe);
 
while(1){ Atomic.sleep(10000); } // veg out while other talk</langsyntaxhighlight>
{{out}}
Terminal 1:
10,327

edits