Sep-24-2023, 11:09 AM
(Sep-23-2023, 01:32 PM)snippsat Wrote:(Sep-23-2023, 12:01 PM)akbarza Wrote: I think the code is used for running Firefox from inside Python. is it true?Yes it will try to run the FireFox binary,but i think you misunderstand how this work.
why did not the code run successfully?
As the Firefox(Browser) is a long running process and may give no output tostdout
at all.
Theeval
make no sense here,can only use Python eval if output make any sense for this and are secure for task like this.
To give example of that make some sense,so eg when runping
on command line,
it give output about request messages to a target Ip.
import subprocess response = subprocess.run(['ping', '-n' ,'4', 'python-forum.io'], capture_output=True, encoding='utf-8') print(response.stdout)So now in subprocess running the ping command and capture is output.
Output:Pinging python-forum.io [2606:4700:3035::6815:1b29] with 32 bytes of data: Reply from 2606:4700:3035::6815:1b29: time=37ms Reply from 2606:4700:3035::6815:1b29: time=26ms Reply from 2606:4700:3035::6815:1b29: time=37ms Reply from 2606:4700:3035::6815:1b29: time=42ms Ping statistics for 2606:4700:3035::6815:1b29: Packets: Sent = 4, Received = 4, Lost = 0 (0% loss), Approximate round trip times in milli-seconds: Minimum = 26ms, Maximum = 42ms, Average = 35ms
Alsosubprocess.getoutput()
is not common used at all.
Doc Wrote:Using the subprocess Module
The recommended approach to invoking subprocesses is to use therun()
function for all use cases it can handle.
For more advanced use cases, the underlyingPopen
interface can be used directly.
hi snippet
I am not familiar with the subprocess library and your code:
response = subprocess.run(['ping', '-n' ,'4', 'python-forum.io'], capture_output=True, encoding='utf-8')how(where) can I gain more info about the above code?
do you have any opinion about my second question?
thanks a lot.