When you click on the Terminal icon on your Desktop you are loading a program which in turn loads a shell. The commands you write are not executed directly by the kernel but are first interpreted by the shell.
Command (eg. `ls -l')
↓
Terminal Program (eg. `gnome-terminal')
↓
Shell (eg Bash)
↓
Kernel (eg. Linux 2.6.24)
More information about shells:
http://en.wikipedia.org/wiki/Unix_shell
More information about how processes are actually started:
http://pangea.stanford.edu/computerinfo/unix/shell/processes/processes.html
When you execute a program from Python you can choose to execute it directly with the kernel or via a shell. If you are executing it directly you won't be able to write your commands in quite the same way as you would when using a shell like bash.
Let's look at the different functionality you will be used to using on the shell before looking at how to achive similar results with subprocess.
Streams
In UNIX and Linux, there are three I/O channels known as streams which connect a computer program with its environment such as a text terminal (eg gnome-terminal' running Bash) or another computer program (eg a Python program using the ``subprocess` module). These I/O channels are called the standard input, standard output and standard error respectively and can also be refered to by their corresponding file descriptors which are the numbers 0, 1 and 2 respectively.
Handle Name Description
0 stdin Standard input
1 stdout Standard output
2 stderr Standard error
Here you can see that standard input is often called stdin, standard output called stdout and standard error called stderr.
The streams work as follows: input from the terminal is sent via the standard input stream to the program, normal output is returned from the program via the standard output and error messages are returned to the environment standard error.
Command (eg. `ls -l')
↓
Terminal Program (eg. `gnome-terminal')
↓
Shell (eg Bash)
↓
Kernel (eg. Linux 2.6.24)
More information about shells:
http://en.wikipedia.org/wiki/Unix_shell
More information about how processes are actually started:
http://pangea.stanford.edu/computerinfo/unix/shell/processes/processes.html
When you execute a program from Python you can choose to execute it directly with the kernel or via a shell. If you are executing it directly you won't be able to write your commands in quite the same way as you would when using a shell like bash.
Let's look at the different functionality you will be used to using on the shell before looking at how to achive similar results with subprocess.
Streams
In UNIX and Linux, there are three I/O channels known as streams which connect a computer program with its environment such as a text terminal (eg gnome-terminal' running Bash) or another computer program (eg a Python program using the ``subprocess` module). These I/O channels are called the standard input, standard output and standard error respectively and can also be refered to by their corresponding file descriptors which are the numbers 0, 1 and 2 respectively.
Handle Name Description
0 stdin Standard input
1 stdout Standard output
2 stderr Standard error
Here you can see that standard input is often called stdin, standard output called stdout and standard error called stderr.
The streams work as follows: input from the terminal is sent via the standard input stream to the program, normal output is returned from the program via the standard output and error messages are returned to the environment standard error.
Comments
Post a Comment
https://gengwg.blogspot.com/