Blocking ctrl-c to os.popen() or os.system()

Sandeep Gupta sandeep182 at hotmail.com
Sat Jan 4 21:41:45 EST 2003


Unfortunately, python doesn't see the ctrl-c when it is typed during the
command, so there is no KeyboardInterrupt.

Thanks for the idea...

"pythonhda" <pythonhda at yahoo.com.replacepythonwithlinux> wrote in message
news:20030104213812.04f3dd44.pythonhda at yahoo.com.replacepythonwithlinux...
> Maybe you can try to catch the exception?
>
> while doing_something:
> try:
> .....
> except KeyboardInterrupt:
> print "I'm not done yet"
>
>
>
> On 4 Jan 2003 14:00:35 -0800
> sandeep182 at hotmail.com (Sandeep Gupta) wrote:
>
> > I am executing a command from python via os.popen().  While the
> > command is executing, if I type ctrl-c, the command receives the
> > interrupt.  I would like to block the ctrl-c from the command and I've
> > tried the following:
> >
> > 1)Using python's signal module to ignore SIGINT.  This causes python
> > to ignore SIGINT, but a ctrl-c that is typed during the popen() call
> > still goes to the command.
> >
> > 2)Adding "< /dev/null" to the os.popen() call.  This doesn't help.
> >
> > 3)Using popen2() and immediately closing the stdin file.  This also
> > doesn't work.
> >
> > Any suggestions would be greatly appreciated!
> >
> > Thanks
> > Sandeep






More information about the Python-list mailing list