Re: send command to parent shell
Martin Landa landa.mar...@gmail.com writes: 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: send command to parent shell
On Wed, 13 Oct 2010 06:30:15 -0700, Martin Landa wrote: 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/): giampa...@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. import psutil, os me = psutil.Process(os.getpid()) me.name 'python' parent = me.parent parent.name 'bash' parent.kill() Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ -- http://mail.python.org/mailman/listinfo/python-list
Re: send command to parent shell
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à g.rod...@gmail.com: On Wed, 13 Oct 2010 06:30:15 -0700, Martin Landa wrote: 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/): giampa...@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. import psutil, os me = psutil.Process(os.getpid()) me.name 'python' parent = me.parent parent.name 'bash' parent.kill() Regards, --- Giampaolo http://code.google.com/p/pyftpdlib/ http://code.google.com/p/psutil/ -- http://mail.python.org/mailman/listinfo/python-list
send command to parent shell
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: send command to parent shell
On Wed, 13 Oct 2010 06:30:15 -0700, Martin Landa wrote: 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. -- http://mail.python.org/mailman/listinfo/python-list