473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

subprocesses, stdin/out, ttys, and beating insubordinate processesinto the ground

First a bit about what I'm trying to do. I need a function which takes a
patchfile and patches a source directory. Thats it. However, I need to
be able to do so no matter what the patchlevel (-px) of the diff is. So,
my solution is to just try to patch until it works or you try a level
more than 3. However, if you have a reversed patch, or patch can't find
the right file, GNU patch tries to ask for input and I don't want that.
I know that patch will run non-interactively when backgrounded in a
shell (no controlling tty). This is what I've tried so far:

def patchme(self, provides, f, destDir, patchlevels):
for patchlevel in patchlevels:
patchArgs = ['patch', '-d', destDir, '-p%s'%patchlevel, ]
if self.backup:
patchArgs.append(['-b', '-z', self.backup])
if self.extraArgs:
patchArgs.append(self.extraArgs)

log.info('attempting to patch the source with file %s and
patchlevel %s' % (f,patchlevel))
p1 = subprocess.Popen([provides, f],
stdout=subprocess.PIPE, shell=False)
p2 = subprocess.Popen(patchArgs, stdin=p1.stdout, shell=False)
message = p2.communicate()[0] # patch seems to use stdout
for everything, even errors

if message != None and self.patcherror.search(message):
os.kill(p2.pid, signal.SIGTERM)
elif p2.wait():
log.info('patch did not apply with path level %s' %
patchlevel)
print message
else:
return
log.error('could not apply the patch to your build dir')
However, I still get an interactive prompt, no matter what I try! Using
shell=False did not help, nor did trying to kill the pid if python sees
a line from patch which isn't saying what its patching or giving info on
a specific hunk. Any suggestions?

-smithj

PS: if you're a maintainer for GNU patch, a --non-interactive would be
really nice ;-) (and no, -f and -t aren't good enough as they force
other things that I don't want)
Jun 6 '06 #1
0 1000

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jane Austine | last post by:
Running Python 2.3 on Win XP It seems like socket is working interdependently with subprocesses of the process which created socket. ------------------------------------ #the server side >>>...
2
by: Marcos | last post by:
Hi guys, I realise this question has been answered in one form or another many times before but I can't quite find the solution I need. I am trying to run multiple subprocesses from a python...
0
by: lickspittle | last post by:
Hi, I have Python embedded with my other code, and when my other code opens a console and redirects stdout, stdin and stderr to it, then calls PyRun_InteractiveLoop, it immediately returns with...
2
by: Dave Kirby | last post by:
I am working on a network management program written in python that has multiple threads (typically 20+) spawning subprocesses which are used to communicate with other systems on the network. This...
3
by: Harayasu | last post by:
Hi, Using fgets() I can read from stdin and with fputs() I can write to stdout. Now I have two programs, one writing to stdin and the other one reading from stdin. And I would like the second...
23
by: herrcho | last post by:
What's the difference between STDIN and Keyboard buffer ? when i get char through scanf, i type in some characters and press enter, then, where do the characters go ? to STDIN or Keyboard...
3
by: Dara Durum | last post by:
Hi ! Py2.4, Win32. I need to optimize a program that have a speciality: hash (MD5/SHA1) the file contents (many files). Now I do this in a simple python program, because (what a pity) the...
1
by: betatim | last post by:
Hi, there are many ways of solving the problem of finite buffer sizes when talking to a subprocess. I'd usually suggest using select() but today I was looking for a more readable/understandable...
1
by: Gal Diskin | last post by:
Hi all, I'm writing a python program using threads to open several subprocesses concurrently (using module subprocess) and wait on them. I was wondering if there is a possibilty that a thread will...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.