[英]On Python, How to open multiple command windows simultaneously (in cascade)
我打算监视连接(通过 ping)3 台设备进入 .net。 到目前为止,我尝试了以下脚本,但在某些脚本中,命令在单个 windows import os import multiprocessing 中运行
def xxx():
while True:
os.system('cmd /c "ping 192.168.1.254 -t " ')
if __name__ == '__main__':
jobs = []
for i in range(3 ):
p = multiprocessing.Process(target=xxx)
jobs.append(p)
p.start()
# _______________________________________________________
import threading
import os
def xxx():
os.system('cmd /c "ping 192.168.1.254 -t " ')
def yyy():
os.system('cmd /c "ping 127.1.1.0 -t " ')
def main():
server_thread = threading.Thread(target=xxx)
client_thread = threading.Thread(target=yyy)
server_thread.start()
client_thread.start()
#__________________________________________________
import os
import multiprocessing
def xxx():
os.system( 'cmd /c "ping 192.168.1.254 -t " ')
def yyy():
os.system('cmd /c "ping 127.1.1.0 -t "')
if __name__ == '__main__':
jobs = []
p = multiprocessing.Process(target=xxx)
jobs.append(p)
p.start()
q = multiprocessing.Process(target=yyy)
jobs.append(q)
q.start()
也许只是运行另一个 Python 脚本,您可以在其中放置 ping 方法或其他来自主脚本的方法
subprocess.call('python ping_script.py', shell=True)
但是如果你想对你的流程有一些直观的了解,我建议你使用 Jupyter notebooks
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.