ホームページ >バックエンド開発 >Python チュートリアル >Python バッチ送信サンドボックスの問題の例
この記事の例では、Python バッチ送信サンドボックスの問題について説明しており、参考のために全員と共有されています。具体的な方法は以下の通りです。
発生する問題は次のとおりです:
1. Linux で Popen を使用する場合、パラメータは文字列ではなくリストで渡されます。それ以外の場合、「OSErrorr: [Errno 2] No such file or directory」というエラーが発生する可能性があります。
2. shutil モジュールを使用してリストをコピーする必要があります。そうしないと、最初のサンプルが送信された後、後続の送信パラメータが間違ったものになります。コードは次のとおりです:
import os from subprocess import Popen class SubmitCuckoo: """""" def __init__(self, dirctory): """Constructor""" self._dirctory = dirctory self._pargs = ["/usr/bin/python", "/home/xxx/xxx/submit.py"] def _file_callback(self, file_path): args = ["/usr/bin/python", "/home/xx/xxx/submit.py"] args.append(file_path) print "args:",args Popen(args) def submit_cuckoo(self, file_callback=_file_callback): """ """ dir = self._dirctory for root, dirs, files in os.walk(dir): for f in files: file_path = os.path.join(root, f) if file_callback: file_callback(self, file_path) if __name__ == "__main__": submit_cuckoo = SubmitCuckoo(r"/home/xxx/xxx/samples") submit_cuckoo.submit_cuckoo()この記事が皆さんの Python プログラミング設計に役立つことを願っています。