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
31f182e8
Kaydet (Commit)
31f182e8
authored
Agu 28, 2000
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Added os.popen2() and os.popen3() for non-Windows platforms.
üst
e67d8e51
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
4 deletions
+57
-4
os.py
Lib/os.py
+13
-0
popen2.py
Lib/popen2.py
+5
-3
test_popen2
Lib/test/output/test_popen2
+5
-0
test_popen2.py
Lib/test/test_popen2.py
+34
-1
No files found.
Lib/os.py
Dosyayı görüntüle @
31f182e8
...
...
@@ -454,3 +454,16 @@ otherwise return -SIG, where SIG is the signal that killed it. """
return
spawnvpe
(
mode
,
file
,
args
[:
-
1
],
env
)
if
not
_exists
(
"popen2"
):
def
popen2
(
cmd
,
mode
=
"t"
,
bufsize
=-
1
):
assert
mode
[:
1
]
in
(
"b"
,
"t"
)
import
popen2
stdout
,
stdin
=
popen2
.
popen2
(
cmd
,
bufsize
)
return
stdin
,
stdout
if
not
_exists
(
"popen3"
):
def
popen3
(
cmd
,
mode
=
"t"
,
bufsize
=-
1
):
assert
mode
[:
1
]
in
(
"b"
,
"t"
)
import
popen2
stdout
,
stdin
,
stderr
=
popen2
.
popen3
(
cmd
,
bufsize
)
return
stdin
,
stdout
,
stderr
Lib/popen2.py
Dosyayı görüntüle @
31f182e8
...
...
@@ -89,7 +89,8 @@ class Popen3:
_active
.
remove
(
self
)
return
self
.
sts
if
hasattr
(
os
,
"popen2"
):
if
sys
.
platform
[:
3
]
==
"win"
:
def
popen2
(
cmd
,
mode
=
't'
,
bufsize
=-
1
):
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
specified, it sets the buffer size for the I/O pipes. The file objects
...
...
@@ -109,7 +110,7 @@ else:
inst
=
Popen3
(
cmd
,
0
,
bufsize
)
return
inst
.
fromchild
,
inst
.
tochild
if
hasattr
(
os
,
"popen3"
)
:
if
sys
.
platform
[:
3
]
==
"win"
:
def
popen3
(
cmd
,
mode
=
't'
,
bufsize
=-
1
):
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
specified, it sets the buffer size for the I/O pipes. The file objects
...
...
@@ -129,7 +130,7 @@ else:
inst
=
Popen3
(
cmd
,
1
,
bufsize
)
return
inst
.
fromchild
,
inst
.
tochild
,
inst
.
childerr
if
hasattr
(
os
,
"popen4"
)
:
if
sys
.
platform
[:
3
]
==
"win"
:
def
popen4
(
cmd
,
mode
=
't'
,
bufsize
=-
1
):
"""Execute the shell command 'cmd' in a sub-process. If 'bufsize' is
specified, it sets the buffer size for the I/O pipes. The file objects
...
...
@@ -139,6 +140,7 @@ if hasattr(os, "popen4"):
else
:
pass
# not yet on unix
def
_test
():
cmd
=
"cat"
teststr
=
"abc
\n
"
...
...
Lib/test/output/test_popen2
Dosyayı görüntüle @
31f182e8
test_popen2
Test popen2 module:
testing popen2...
testing popen3...
All OK
Testing os module:
testing popen2...
testing popen3...
All OK
Lib/test/test_popen2.py
Dosyayı görüntüle @
31f182e8
...
...
@@ -3,12 +3,15 @@
Christian Tismer
"""
import
os
# popen2 contains its own testing routine
# which is especially useful to see if open files
# like stdin can be read successfully by a forked
# subprocess.
def
main
():
print
"Test popen2 module:"
try
:
from
os
import
popen
except
ImportError
:
...
...
@@ -19,5 +22,35 @@ def main():
import
popen2
popen2
.
_test
()
main
()
def
_test
():
# same test as popen2._test(), but using the os.popen*() API
print
"Testing os module:"
import
popen2
cmd
=
"cat"
teststr
=
"abc
\n
"
resultstr
=
teststr
if
os
.
name
==
"nt"
:
cmd
=
"more"
resultstr
=
"
\n
"
+
resultstr
print
"testing popen2..."
w
,
r
=
os
.
popen2
(
cmd
)
w
.
write
(
teststr
)
w
.
close
()
assert
r
.
read
()
==
resultstr
print
"testing popen3..."
try
:
w
,
r
,
e
=
os
.
popen3
([
cmd
])
except
:
w
,
r
,
e
=
os
.
popen3
(
cmd
)
w
.
write
(
teststr
)
w
.
close
()
assert
r
.
read
()
==
resultstr
assert
e
.
read
()
==
""
for
inst
in
popen2
.
_active
[:]:
inst
.
wait
()
assert
not
popen2
.
_active
print
"All OK"
main
()
_test
()
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