これが重複していないことを願っています。
subprocess.Popen()
別のコンソールでスクリプトを開くために使用しようとしています。shell=True
パラメータを設定しようとしましたが、うまくいきませんでした。
64 ビットの Windows 7 で 32 ビットの Python 2.7 を使用しています。
これが重複していないことを願っています。
subprocess.Popen()
別のコンソールでスクリプトを開くために使用しようとしています。shell=True
パラメータを設定しようとしましたが、うまくいきませんでした。
64 ビットの Windows 7 で 32 ビットの Python 2.7 を使用しています。
from subprocess import *
c = 'dir' #Windows
handle = Popen(c, stdin=PIPE, stderr=PIPE, stdout=PIPE, shell=True)
print handle.stdout.read()
handle.flush()
使用しない場合は、コマンド文字列の代わりにリストをshell=True
指定する必要があります。例:Popen()
c = ['ls', '-l'] #Linux
次に、シェルなしで開きます。
handle = Popen(c, stdin=PIPE, stderr=PIPE, stdout=PIPE)
print handle.stdout.read()
handle.flush()
これは、Python からサブプロセスを呼び出す最も手動で柔軟な方法です。出力だけが必要な場合は、次のようにします。
from subproccess import check_output
print check_output('dir')
import os
os.system("start cmd /K dir") #/K remains the window, /C executes and dies (popup)