代码不上传,而是在控制台中打印

问题描述 投票:0回答:1

我已经制作了这个代码,它应该上传一些内容,但它不会上传任何内容,只是在我的控制台中打印命令的结果,并且不会上传任何内容到网站

import requests, os, re, subprocess
from bs4 import BeautifulSoup

command = 'netsh interface ip show addresses "Ethernet" | findstr /c:IP'
outcome = str(subprocess.Popen(command, shell=True).wait())
#soup = BeautifulSoup(outcome,'lxml')

#outcome = outcome.replace('0','')

#print str(subprocess.call(command, shell=True))

requests.post("example.com", {'field1': outcome})

和控制台输出:

IP Address:                           192.168.1.23

这个上传到网站0

我试过了:

import requests, os, re, subprocess
from bs4 import BeautifulSoup

command = 'netsh interface ip show addresses "Ethernet" | findstr /c:IP'
#subprocess.communicate(command, shell=True)
subprocess.Popen(command, shell=True).communicate()
outcome = subprocess.PIPE
#soup = BeautifulSoup(outcome,'lxml')

#outcome = outcome.replace('0','')

#print str(subprocess.call(command, shell=True))

requests.post("example.com", {'field1': outcome})

和控制台输出:

IP Address:                           192.168.1.23

这个上传到网站-1

我想要它做的是将该IP地址结果上传到网站。

python python-2.7 python-requests
1个回答
0
投票

您没有正确使用子进程。我建议你使用subprocess.Popen.communicate,并传入stdout = subprocess.PIPE来实际获取子进程的stdout。

p = subprocess.Popen(["my", "command"], stdout=subprocess.PIPE)
stdout, _ = p.communicate()
© www.soinside.com 2019 - 2024. All rights reserved.