send command to parent shell

M

Martin Landa

Hi,

is there a way how to send command from python script to the shell
(known id) from which the python script has been called? More
precisely, the goal is to exit running bash (on Linux) or cmd (on
Windows) directly from wxPython application, currently user needs to
quit wxPython application and then underlaying command prompt by
'exit' command.

Thanks in advance, Martin
 
N

Nobody

is there a way how to send command from python script to the shell
(known id) from which the python script has been called?

For Unix, this should work, but in general it's the wrong thing to do:

import os
import signal
os.kill(os.getppid(), signal.SIGKILL)

This is a rather unfriendly way to kill the shell (it won't be able to
save its history, etc), and if the program was started from something
other than a shell, you might kill something you don't want to.

Using SIGHUP is more friendly and will probably work, but it could be
caught and/or ignored (for bash, SIGTERM, SIGQUIT and SIGINT /will/ be
ignored). If the shell can catch the signal in order to save its history,
it can catch it and ignore it.

There isn't a nice way to do it. There isn't supposed to be a nice way to
do it. Processes may control their children, but a child isn't supposed to
control its parent.
 
D

Diez B. Roggisch

Martin Landa said:
Hi,

is there a way how to send command from python script to the shell
(known id) from which the python script has been called? More
precisely, the goal is to exit running bash (on Linux) or cmd (on
Windows) directly from wxPython application, currently user needs to
quit wxPython application and then underlaying command prompt by
'exit' command.

Why is it started from the shell then in the first place? And if I did
it, I beg you to *not* close it... if I wanted that, I would have used

exec program

Diez
 
G

Giampaolo Rodolà

G

Giampaolo Rodolà

Sorry I realize now that you wrote "how to send a command to the
shell" and not "how to kill the shell".
In this case I don't know exactly what you mean.



Regards,

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/

2010/10/14 Giampaolo Rodolà said:
is there a way how to send command from python script to the shell
(known id) from which the python script has been called?

By using psutil (http://code.google.com/p/psutil/):

giampaolo@ubuntu:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Regards,

--- Giampaolo
http://code.google.com/p/pyftpdlib/
http://code.google.com/p/psutil/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top