Bash リファレンスによると、& 文字で終わって非ブロックコマンドを発行できます。ただし、次のコマンドを試しても機能しません。
python -m SimpleHTTPServer 8080&
私がこれを計画しているのは、Pythonで書かれた別の大規模なプログラムの一部として組み込まれたPython Webサーバーを起動したいからです。非ブロック/デーモンモードでこのコマンドをどのように実行できますか?非ブロックプロセスも生成する必要がある「subprocess.Popen()」を使用してPythonでこのコマンドを実行してみましたが、それも機能しません。
編集:これはWebサーバーを起動するPythonコードの一部です(「nohup」を追加すると効果があるようです)。
pid_webserver = execute("nohup python -m SimpleHTTPServer 8080 &",wait=False,shellexec= True)
#pid_webserver = execute("python -m SimpleHTTPServer 8080 &",wait=False,shellexec= True)
def execute(command,errorstring='', wait = True, shellexec = True):
try:
print 'command=' + command
p=subprocess.Popen("gksu '" + command + "'", shell=shellexec,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
if wait:
p.wait()
result=get_stdout(p)
return result
else:
print 'not waiting'
return p
except subprocess.CalledProcessError as e:
print 'error occured:' + errorstring
return errorstring
ベストアンサー1
働く&
。しかし、私の考えであなたが探しているのはnohup python -m SimpleHTTPServer &
。
しかし、あなたも確認してみるべきだと思います。http://docs.python.org/2/library/simplehttpserver.html。