0

こんにちは、コーディングの世界のすべての初心者です。Python で自動化プロジェクトを実行し、wxPython を使用して GUI をシェル スクリプト化する

私のコードは次のとおりです。

      z = subprocess.Popen(["ps aux | grep 'process1' | grep -v grep"],shell=True, stdout = subprocess.PIPE)
      connect = z.stdout.readlines()
      connect = "".join(connect)
      if connect is None:  # connect == ' ':
         self.info = wx.MessageBox("Not able to proceed","warning", wx.OK)
      else:

         self.permission = wx.MessageBox("Can enter","warning", wx.OK)

ただし、プロセス 1 が実行されていない場合は、self.permission メッセージ ボックス、つまり「入ることができます」も表示されます。ここで私が間違っていることは何ですか。

4

2 に答える 2

1

connectここにいることはできませんNone:

  connect = z.stdout.readlines()
  connect = "".join(connect)
  if connect is None:  # connect == ' ':

If it was, the line before if would throw exception. It can probably be an empty string, so you can change the test as follows:

  if not connect:
于 2013-06-26T10:26:06.727 に答える
1
if not connect: 

instead of

if connect is None. 

It must work

于 2013-06-26T10:26:14.753 に答える