Python Forum
Understanding subprocess.Popen
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Understanding subprocess.Popen
#1
The code I use is from here, Part 5

Just playing around with generators, I have a Python script to simulate a log file which is constantly updated, then another script, follow.py to get the last line of the log file.

In the instructions it says, I should use subprocess like this:

# the file logsim.py is here: '/home/pedro/myPython/yield/tutorial2008/generators/run/foo/logsim.py'
# navigate to /home/pedro/myPython/yield/tutorial2008 in bash
# then enter ./runserver.py
# but this does not work
p1 = subprocess.Popen(['python','logsim.py'], cwd='generators/run/foo')
But I get this error

Quote:# FileNotFoundError: [Errno 2] No such file or directory: 'python'

However this works fine:

foofile = '/home/pedro/myPython/yield/tutorial2008/generators/run/foo/logsim.py'
p1 = subprocess.Popen([foofile], cwd='generators/run/foo')
I don't understand subprocess.Popen(). The cwd command does not seem to work.

What should I actually put in subprocess.Popen()?

The whole script, which works fine, is this:

#! /usr/bin/python3
# runservers.py
# a simulated log file
import subprocess
import time

print("Running simulated web servers")
print() 
print("This runs a simulated server that writes these log files")
print()
print("run/foo/access.log")
print("run/bar/access.log")
print()
print("Please leave this running as a background process while")
print("working on examples related to infinite input streams")

#p1 = subprocess.Popen(['python','logsim.py'], cwd='generators/run/foo')
foofile = '/home/pedro/myPython/yield/tutorial2008/generators/run/foo/logsim.py'
p1 = subprocess.Popen([foofile], cwd='generators/run/foo')
time.sleep(600)
#p2 = subprocess.Popen(['python','logsim.py'], cwd='generators/run/bar')
barfile = '/home/pedro/myPython/yield/tutorial2008/generators/run/bar/logsim.py'
p2 = subprocess.Popen([barfile], cwd='generators/run/bar')
p1.wait()
p2.wait()
Reply


Messages In This Thread
Understanding subprocess.Popen - by Pedroski55 - May-12-2024, 07:30 AM
RE: Understanding subprocess.Popen - by Gribouillis - May-12-2024, 07:57 AM
RE: Understanding subprocess.Popen - by Pedroski55 - May-12-2024, 09:54 AM
RE: Understanding subprocess.Popen - by Gribouillis - May-12-2024, 10:07 AM
RE: Understanding subprocess.Popen - by Pedroski55 - May-12-2024, 10:20 AM
RE: Understanding subprocess.Popen - by Gribouillis - May-12-2024, 10:22 AM
RE: Understanding subprocess.Popen - by Pedroski55 - May-12-2024, 10:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Information subprocess.Popen() suddenly giving me grief? davecotter 3 818 Dec-13-2023, 10:49 PM
Last Post: davecotter
  Use subprocess.Popen and time.sleep chucky831 2 2,067 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  Subprocess.Popen() not working when reading file path from csv file herwin 13 16,182 May-07-2021, 03:26 PM
Last Post: herwin
  Did subprocess.Popen() causes main routine to pause stdout? liudr 4 3,833 May-04-2021, 08:58 PM
Last Post: liudr
  disable subprocess.popen prompt echo paul18fr 1 2,147 Feb-04-2021, 02:50 AM
Last Post: Larz60+
  how to pass the interactive string to Popen subprocess maiya 1 2,001 Sep-18-2020, 09:36 PM
Last Post: Larz60+
  How to get program output from subprocess.Popen? glestwid 1 2,477 Aug-19-2020, 05:44 AM
Last Post: buran
  subprocess.Popen() and encodings voltron 0 5,924 Feb-20-2020, 04:57 PM
Last Post: voltron
  Mock call to subprocess.Popen failing with StopIteration tharpa 7 6,192 Nov-08-2019, 05:00 PM
Last Post: Gribouillis
  no coding= option fo subprocess.Popen() Skaperen 5 5,967 Jun-21-2019, 10:24 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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