如何验证subprocess.check_output()?

时间:2015-12-01 06:09:54

标签: python

我正在通过subprocess.check_output()执行命令,因为我希望它的o / p存储在缓冲区中。

现在,在执行此操作时,如果命令失败或者出现任何错误,则会导致整个应用程序出现问题。

我想要的是,即使命令失败,它也应该打印并继续下一条指令。

有人可以帮我解决吗?

以下是示例代码。

from subprocess import check_output
buff=check_output(["command","argument"])
if buff=="condition":
    print "Do Some Task "

1 个答案:

答案 0 :(得分:0)

执行此操作的一种方法是在Android: mGatt null and connectGatt called 12-01 11:24:17.811 I/mono-stdout(19643): Android: mGatt null and connectGatt called 12-01 11:24:17.815 D/BluetoothDevice(19643): mAddress: 00:A0:50:18:1F:0A 12-01 11:24:17.816 D/BluetoothGatt(19643): connect() - device: 00:A0:50:18:1F:0A, auto: false 12-01 11:24:17.816 D/BluetoothGatt(19643): registerApp() 12-01 11:24:17.816 D/BluetoothGatt(19643): registerApp() - UUID=e290958f-d7dc-4788-9762-99feac2801bf 12-01 11:24:17.820 D/BluetoothGatt(19643): onClientRegistered() - status=0 clientIf=1 12-01 11:24:17.820 D/BluetoothDevice(19643): mAddress: 00:A0:50:18:1F:0A 12-01 11:24:18.119 D/BluetoothGatt(19643): onClientConnectionState() - status=0 clientIf=1 device=00:A0:50:18:1F:0A 12-01 11:24:18.119 D/BluetoothDevice(19643): mAddress: 00:A0:50:18:1F:0A Thread started: #8 Android: OnConnectionStateChange: -Connected 12-01 11:24:18.158 I/mono-stdout(19643): Android: OnConnectionStateChange: -Connected XM> DeviceConnected 12-01 11:24:18.168 I/mono-stdout(19643): XM> DeviceConnected [0:] XM> DeviceConnected XM> Discover Services 12-01 11:24:18.175 I/mono-stdout(19643): XM> Discover Services [0:] XM> Discover Services 12-01 11:24:18.179 D/BluetoothDevice(19643): mAddress: 00:A0:50:18:1F:0A 12-01 11:24:18.179 D/BluetoothGatt(19643): discoverServices() - device: 00:A0:50:18:1F:0A 12-01 11:24:18.179 D/BluetoothDevice(19643): mAddress: 00:A0:50:18:1F:0A Android: DiscoverServices - Bool - True 12-01 11:24:18.180 I/mono-stdout(19643): Android: DiscoverServices - Bool - True 12-01 11:24:21.368 D/BluetoothGatt(19643): onClientConnectionState() - status=0 clientIf=1 device=00:A0:50:18:1F:0A 12-01 11:24:21.368 D/BluetoothDevice(19643): mAddress: 00:A0:50:18:1F:0A Thread started: #9 Android: OnConnectionStateChange: -Disconnected 12-01 11:24:21.387 I/mono-stdout(19643): Android: OnConnectionStateChange: -Disconnected Thread finished: <Thread Pool> #7 The thread 'Unknown' (0x7) has exited with code 0 (0x0). 实例上使用Popen.communicate方法。

Process