Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
8161a65c
Kaydet (Commit)
8161a65c
authored
Kas 12, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add -i option. Don't exit when the command fails. Redirect stderr to stdout.
üst
db4a2ef2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
12 deletions
+34
-12
repeat.py
Demo/curses/repeat.py
+34
-12
No files found.
Demo/curses/repeat.py
Dosyayı görüntüle @
8161a65c
#! /usr/bin/env python
#! /usr/bin/env python
"""repeat <shell-command>
"""repeat
[-i SECONDS]
<shell-command>
This simple program repeatedly (at 1-second intervals) executes the
This simple program repeatedly (at 1-second intervals) executes the
shell command given on the command line and displays the output (or as
shell command given on the command line and displays the output (or as
...
@@ -9,6 +9,8 @@ output on top of the old output, so that if nothing changes, the
...
@@ -9,6 +9,8 @@ output on top of the old output, so that if nothing changes, the
screen doesn't change. This is handy to watch for changes in e.g. a
screen doesn't change. This is handy to watch for changes in e.g. a
directory or process listing.
directory or process listing.
The -i option lets you override the sleep time between executions.
To end, hit Control-C.
To end, hit Control-C.
"""
"""
...
@@ -24,18 +26,30 @@ import os
...
@@ -24,18 +26,30 @@ import os
import
sys
import
sys
import
time
import
time
import
curses
import
curses
import
getopt
def
main
():
def
main
():
if
not
sys
.
argv
[
1
:]:
interval
=
1.0
try
:
opts
,
args
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"hi:"
)
except
getopt
.
error
as
err
:
print
(
err
,
file
=
sys
.
stderr
)
sys
.
exit
(
2
)
if
not
args
:
print
(
__doc__
)
print
(
__doc__
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
cmd
=
" "
.
join
(
sys
.
argv
[
1
:])
for
opt
,
arg
in
opts
:
p
=
os
.
popen
(
cmd
,
"r"
)
if
opt
==
"-i"
:
interval
=
float
(
arg
)
if
opt
==
"-h"
:
print
(
__doc__
)
sys
.
exit
(
0
)
cmd
=
" "
.
join
(
args
)
cmd_really
=
cmd
+
" 2>&1"
p
=
os
.
popen
(
cmd_really
,
"r"
)
text
=
p
.
read
()
text
=
p
.
read
()
sts
=
p
.
close
()
sts
=
p
.
close
()
if
sts
:
text
=
addsts
(
interval
,
cmd
,
text
,
sts
)
print
(
"Exit code:"
,
sts
,
file
=
sys
.
stderr
)
sys
.
exit
(
sts
)
w
=
curses
.
initscr
()
w
=
curses
.
initscr
()
try
:
try
:
while
True
:
while
True
:
...
@@ -45,14 +59,22 @@ def main():
...
@@ -45,14 +59,22 @@ def main():
except
curses
.
error
:
except
curses
.
error
:
pass
pass
w
.
refresh
()
w
.
refresh
()
time
.
sleep
(
1
)
time
.
sleep
(
interval
)
p
=
os
.
popen
(
cmd
,
"r"
)
p
=
os
.
popen
(
cmd
_really
,
"r"
)
text
=
p
.
read
()
text
=
p
.
read
()
sts
=
p
.
close
()
sts
=
p
.
close
()
if
sts
:
text
=
addsts
(
interval
,
cmd
,
text
,
sts
)
print
(
"Exit code:"
,
sts
,
file
=
sys
.
stderr
)
sys
.
exit
(
sts
)
finally
:
finally
:
curses
.
endwin
()
curses
.
endwin
()
def
addsts
(
interval
,
cmd
,
text
,
sts
):
now
=
time
.
strftime
(
"
%
H:
%
M:
%
S"
)
text
=
"
%
s, every
%
g sec:
%
s
\n
%
s"
%
(
now
,
interval
,
cmd
,
text
)
if
sts
:
msg
=
"Exit status:
%
d; signal:
%
d"
%
(
sts
>>
8
,
sts
&
0xFF
)
if
text
and
not
text
.
endswith
(
"
\n
"
):
msg
=
"
\n
"
+
msg
text
+=
msg
return
text
main
()
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment