Commit 6bada51f authored by epsi sayidina's avatar epsi sayidina

pipe and fork

parent 003a6837
......@@ -41,6 +41,3 @@ main = do
hClose pipein
putStr ""
......@@ -54,7 +54,7 @@ detachDzen2 = do
detachTransset = forkProcess $ do
wSleep 1
system "transset .8 -n dzentop >/dev/null 2"
system "transset .8 -n dzentop >/dev/null"
putStr ""
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
......
......@@ -13,18 +13,6 @@ function sleep (n)
end
end
function exec (command)
local file = assert(io.popen(command, 'r'))
local s = file:read('*all')
file:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- application related function
......@@ -83,7 +71,7 @@ end
-- main
-- remove all dzen2 instance
exec('pkill dzen2')
os.execute('pkill dzen2')
-- run process in the background
detach_dzen2()
......@@ -13,18 +13,6 @@ function sleep (n)
end
end
function exec (command)
local file = assert(io.popen(command, 'r'))
local s = file:read('*all')
file:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
return s
end
-- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ---
-- application related function
......@@ -87,7 +75,7 @@ function detach_transset()
if pid == 0 then -- this is the child process
sleep(1)
exec('transset .8 -n dzentop >/dev/null 2')
os.execute('transset .8 -n dzentop >/dev/null')
else -- this is the parent process
-- nothing
end
......@@ -98,7 +86,7 @@ end
-- main
-- remove all dzen2 instance
exec('pkill dzen2')
os.execute('pkill dzen2')
-- run process in the background
detach_dzen2()
......
......@@ -16,7 +16,7 @@ my $pipein = IO::Pipe->new();
my $hnd_in = $pipein->reader($cmdin);
my $pipeout = IO::Pipe->new();
my $hnd_out = $pipeout->writer($cmdout);
my $hnd_ou = $pipeout->writer($cmdout);
while(<$pipein>) {
print $pipeout $_;
......
#!/usr/bin/perl
# https://github.com/chromatic/modern_perl_book
# http://www.perlmonks.org/?node_id=690463
# http://perltricks.com/article/162/2015/3/27/Gzipping-data-directly-from-Perl/
use warnings;
use strict;
......
#!/usr/bin/perl
# https://github.com/chromatic/modern_perl_book
# http://www.perlmonks.org/?node_id=690463
# http://perltricks.com/article/162/2015/3/27/Gzipping-data-directly-from-Perl/
use warnings;
use strict;
......@@ -67,7 +64,7 @@ sub detach_transset {
return if $pid; # in the parent process
sleep 1;
system('transset .8 -n dzentop >/dev/null 2');
system('transset .8 -n dzentop >/dev/null');
exit;
}
......
......@@ -59,7 +59,7 @@ function detach_transset() {
$pid = pcntl_fork();
if ($pid == 0) {
sleep(1);
system('transset .8 -n dzentop >/dev/null 2');
system('transset .8 -n dzentop >/dev/null');
}
}
......
......@@ -69,7 +69,7 @@ def detach_transset():
if pid == 0:
try:
time.sleep(1)
os.system('transset .8 -n dzentop >/dev/null 2')
os.system('transset .8 -n dzentop >/dev/null')
os._exit(1)
finally:
os.kill(pid, signal.SIGTERM)
......
......@@ -6,8 +6,4 @@ cmdin = 'conky -c ' + path + '/conky.lua'
cmdout = 'less' # or 'dzen2'
cmd = cmdin + ' | ' + cmdout
system(cmd)
system(cmd)
......@@ -46,7 +46,7 @@ end
def detach_transset()
pid = fork do
sleep(1)
system('transset .8 -n dzentop >/dev/null 2')
system('transset .8 -n dzentop >/dev/null')
end
Process.detach(pid)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment