Chỉ đọc Executing BASH from Python, sau đó 17.1. subprocess — Subprocess management — Python v2.7.3 documentation và tôi đã thấy đối số executable
; và có vẻ như để làm việc:
$ python
Python 2.7.1+ (r271:86832, Sep 27 2012, 21:16:52)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> print os.popen("echo $0").read()
sh
>>> import subprocess
>>> print subprocess.call("echo $0", shell=True).read()
/bin/sh
>>> print subprocess.Popen("echo $0", stdout=subprocess.PIPE, shell=True).stdout.read()
/bin/sh
>>> print subprocess.Popen("echo $0", stdout=subprocess.PIPE, shell=True, executable="/bin/bash").stdout.read()
/bin/bash
>>> print subprocess.Popen("cat <(echo TEST)", stdout=subprocess.PIPE, shell=True).stdout.read()
/bin/sh: Syntax error: "(" unexpected
>>> print subprocess.Popen("cat <(echo TEST)", stdout=subprocess.PIPE, shell=True, executable="/bin/bash").stdout.read()
TEST
Hope this helps ai đó,
Cheers!
Thật vậy,/bin/sh (hầu như luôn luôn là một dạng vỏ bourne) hầu như luôn có ý nghĩa gì khi bất cứ điều gì * nix liên quan nói "vỏ" mà không có trình độ chuyên môn. Nó cũng có thể hữu ích để lưu ý rằng nếu bạn thực sự cần phải thực thi một số đoạn mã trong một shell không bourne cụ thể, bạn có thể truyền hàm như '/ path/to/tcsh -c' đoạn mã tcsh của bạn ở đây ''. –