Home > other >  Python implementation command line how both can real-time display and can get the output?
Python implementation command line how both can real-time display and can get the output?

Time:10-07

Searched for ways to at present, only after the execution, such as once get the output, is there any good way?

No return value:
 OS. System (' ping www.baidu.com) 


Returns a value is performed after a gain, however, can not be real-time display:
 
P=subprocess. Popen (' ping www.baidu.com, shell=True, stdout=subprocess. The PIPE)
Out, err=p.com municate ()
For the line in the out. Splitlines () :
Print (line)

CodePudding user response:

One time of the two methods

CodePudding user response:

reference 1st floor tianfang response:
two methods each performs a

How do you do to make the

CodePudding user response:

With logging libraries can print the debug don't know can meet your need, anyway, logging is to print information will put a good product!

CodePudding user response:

Unless the command is gradually returns results, don't let can only show that command returns a result

CodePudding user response:

reference 4 floor oyljerry response:
unless command is gradually returned as a result, don't let can only display the results of the command returns the

Is a line-by-line, such as ping

CodePudding user response:

Want to display open the web page at the same time, still can obtain the HTML source code?
If so, with the selenium webdriver.

CodePudding user response:

refer to 6th floor seakingx response:
want to show that to open the web page at the same time, still can obtain the HTML source code?
If so, with the selenium webdriver,


Not, it is a command line such as "ping www.baidu.com"
Real-time display the output, and then save,

CodePudding user response:

Ping www.baidu.com - c - 1

CodePudding user response:

Under Linux system using the tee command
Please look at picture

CodePudding user response:

Do you want the crawler www.baidu.com?
Then you can
The import requests

Def test () :
A=requests. Get (http://www.baidu.com)

Print (" shows: a)"

CodePudding user response:

In other blog see method, I use the python3

 
The import subprocess
P=subprocess. Popen (' ping www.baidu.com, shell=True, stdout=subprocess. The PIPE)

For I in iter (p. tdout readline, 'b') :
If not I:
Break
Print (i.d ecode (' GBK '), end=' ')

CodePudding user response:

The original Po: https://blog.csdn.net/xiaoxianerqq/article/details/78844077

CodePudding user response:

I just tried it on, can be so, need to output programs to open a thread running at the same time to save command line results to the log file, and then use the open in the main process and read function to open the log file can be read result of real time, because by & gt;> This way will the command line is written to the file real-time writing can be read in real time and can be successful, so tried many ways to this a little bit seems to be more feasible,
  • Related