May-12-2024, 07:30 AM
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:
However this works fine:
What should I actually put in subprocess.Popen()?
The whole script, which works fine, is this:
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()
