2
That program drips a IP, would like to pick up the result of that ping that is done on this line
os.system ('ping -n 4 {} '.format(ip))
that opens the CMD and drips the IP, and save to any variable, so you can put it in a file .txt
afterward.
import PySimpleGUI
import os
class Tela :
def __init__ (self) :
layout = [
[PySimpleGUI.Text ('ip'),PySimpleGUI.Input(key='ip')],
[PySimpleGUI.Button('enviar')]
]
janela = PySimpleGUI.Window('Dados').layout(layout)
self.button, self.values = janela.Read()
def iniciar (self):
print (self.values)
ip = self.values ['ip']
os.system ('ping -n 4 {} '.format(ip))
return ''
tela1 = Tela()
tela1.iniciar ()
Could you clarify what you want to take and where you want to save?
– Augusto Vasques
This program drops an ip, I would like to take the result of this ping that is done on this line os.system ('ping -n 4 {} '.format(ip)), which opens the cmd and drops the ip, and save in any variable, to be able to put in a file . txt later.
– Gabriel Amorim
you can just use
os.popen()
instead ofos.system
- and call the methodread()
in the return value of it. The new way of doing this, withsubprocess.run
(or worse, subprocess.Popen) which is in the answer complicates too many simple cases. Just put there in theiniciar
:return os.popen(f'ping -n 4 {ip}').read()
- (Unlike "subprocess", "f-strings" simplify, not having to put ". format" )– jsbueno