[resolved] [Python] pipes

oliver11

Как в питоне запустить другую программу и посмотреть, что она написала?
Хочется того, что в Tcl называется [open |/bin/foo r].

Olenenok

 
import os

os.popen
os.popen2
os.popen3
os.popen4
os.system


 popen(command [, mode= r [, bufsize]]) -> pipe
Open a pipe to/from a command returning a file object.
  

os.popenN(cmd, mode=t, buffsize=-1 n=2..4  

 

Execute the shell command cmd in a sub-process. On UNIX, cmd
     may be a sequence, in which case arguments will be passed directly to
     the program without shell intervention (as with os.spawnv. If cmd
     is a string it will be passed to the shell (as with os.system. If
     bufsize is specified, it sets the buffer size for the I/O pipes. The
     file objects (child_stdin, child_stdout) are returned.

 

Execute the shell command cmd in a sub-process. On UNIX, cmd
     may be a sequence, in which case arguments will be passed directly to
     the program without shell intervention (as with os.spawnv. If cmd
     is a string it will be passed to the shell (as with os.system. If
     bufsize is specified, it sets the buffer size for the I/O pipes. The
     file objects (child_stdin, child_stdout, child_stderr) are returned.
  

 

Execute the shell command cmd in a sub-process. On UNIX, cmd
     may be a sequence, in which case arguments will be passed directly to
     the program without shell intervention (as with os.spawnv. If cmd
     is a string it will be passed to the shell (as with os.system. If
     bufsize is specified, it sets the buffer size for the I/O pipes. The
     file objects (child_stdin, child_stdout_stderr) are returned.
 
 
os.system (cmd)  

 
system(command) -> exit_status
Execute the command (a string) in a subshell.

pilot

Не ТруЪ.
17.1 subprocess — Subprocess management
New in version 2.4.
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several other, older modules and functions, such as:
os.system
os.spawn*
os.popen*
popen2.*
commands.*
Information about how the subprocess module can be used to replace these modules and functions can be found in the following sections.

Olenenok

ну да, subprocess.os.popen2 ;)
догоним и перегоним цешарп. :crazy:
Оставить комментарий
Имя или ник:
Комментарий: