Python Forum
problem in using subprocess module
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem in using subprocess module
#3
(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?
why did not the code run successfully?
Yes it will try to run the FireFox binary,but i think you misunderstand how this work.
As the Firefox(Browser) is a long running process and may give no output to stdout at all.
The eval 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 run ping 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)
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
So now in subprocess running the ping command and capture is output.

Also subprocess.getoutput() is not common used at all.
Doc Wrote:Using the subprocess Module

The recommended approach to invoking subprocesses is to use the run() function for all use cases it can handle.
For more advanced use cases, the underlying Popen 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.
Reply


Messages In This Thread
problem in using subprocess module - by akbarza - Sep-23-2023, 12:01 PM
RE: problem in using subprocess module - by akbarza - Sep-24-2023, 11:09 AM
RE: problem in using subprocess module - by akbarza - Sep-24-2023, 11:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with memory_graph module akbarza 3 481 Mar-04-2024, 10:15 AM
Last Post: snippsat
  problem using coloeama module akbarza 3 682 Jan-08-2024, 07:31 AM
Last Post: akbarza
  problem in import module from other folder akbarza 5 1,693 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  problem in using pyqrcode module to create QRcode akbarza 9 2,299 Aug-23-2023, 04:17 PM
Last Post: snippsat
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 1,107 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  Problem with module time and leap seconds Pedroski55 3 1,331 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Question on subprocess module. knoxvilles_joker 3 2,772 Apr-11-2021, 12:51 AM
Last Post: knoxvilles_joker
  keyboard module; must be root problem philipbergwerf 2 19,462 Apr-04-2021, 11:40 AM
Last Post: philipbergwerf
  Problem with Flask Bcrypt import module marcello86 2 5,907 Aug-31-2020, 08:10 PM
Last Post: marcello86
  Js2Py module not found problem Charliedactyl1 5 8,091 Jun-14-2020, 07:39 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020